gpt4 book ai didi

vba - 将突出显示的绿色复制到另一个工作表

转载 作者:行者123 更新时间:2023-12-04 21:54:38 25 4
gpt4 key购买 nike

我设法复制了同一张表中的单元格。但这不是我的主要意图。我应该能够将突出显示的单元格复制到另一个工作表,如 Sheet2 或 Sheet3。我怎么做?

以下是我在同一张纸上复制所做的
Click here to see image

Sub copyHighlight()
Dim ws As Worksheet
Dim lr As Long, i As Long, u As Long

Set ws = ThisWorkbook.Worksheets("Sheet1")

With ws
lr = .Cells(Rows.Count, 1).End(xlUp).Row
If 2 > lr Then Exit Sub

u = 2
For i = 2 To lr
If .Cells(i, 1).Interior.ColorIndex = 4 Then
.Cells(i, 1).Copy .Cells(u, "E")
u = u + 1
End If
Next i
End With

Set ws = Nothing
End Sub

最佳答案

搞清楚如何只复制某些单元格的工作做得很好,这难倒了很多人。

微小变化:添加 Sheets("Sheet2")如下:

Sub copyHighlight()
Dim ws As Worksheet
Dim r As Long, i As Long, u As Long

Set ws = ThisWorkbook.Worksheets("Sheet1")

With ws
lr = .Cells(Rows.Count, 1).End(xlUp).Row
If 2 > lr Then Exit Sub

u = 2
For i = 2 To lr
If .Cells(i, 1).Interior.ColorIndex = 4 Then
.Cells(i, 1).Copy Sheets("Sheet2").Cells(u, "E")
u = u + 1
End If
Next i
End With

Set ws = Nothing
End Sub

关于vba - 将突出显示的绿色复制到另一个工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47430009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com