【发布时间】:2019-07-28 08:04:38
【问题描述】:
我正在努力完成这项工作。
这个宏应该打开一个工作簿(工作簿名称总是会改变,并且总是只有一张表要处理)。这行得通。
设置整个工作表的范围;工作正常。
然后在整个工作表中搜索以黄色突出显示的单元格,然后将这些单元格复制到新工作表中......这就是我需要帮助的地方!
我对 VBA 真的很陌生,这就是我目前所拥有的:
Option Explicit
Sub test3()
Dim data As Variant
Dim rngTemp As Range
Dim cell As Range
'//open Workbook
data = Application.GetOpenFilename(, , "Open Workbook")
Workbooks.Open data
'// set Range ( Whole Sheet)
Set rngTemp = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
If Not rngTemp Is Nothing Then
Range(Cells(1, 1), rngTemp).Select
End If
'// Search for Yellow highlighted Cells and (if you find one)
'// Copy Cell B1 + the 3rd Cell in the column (of the highlighted Cell) + the value highlighted Cell
'// and paste in new Sheet
For Each cell In rngTemp.Cells
If rngTemp.Interior.ColorIndex = 6 Then
cell.Select
Selection.Copy
Sheets.Add
Range("A1").PasteSpecial
Application.CutCopyMode = False
End If
Next
End Sub
【问题讨论】:
-
您需要将每个突出显示的单元格放在不同的工作表上吗?都在同一张纸上?每行?每列?
-
您正在循环通过
rngTemp这只是一个单元格。 -
不,我需要每列一张表中所有突出显示的单元格
标签: excel vba copy-paste