方法'Select'作用于对象'Range'时失败
Sub 集合()
Dim i, a, b, c
For j = 1 To Sheets.Count
i = 1
Set a = Sheets(j).Range("A1").CurrentRegion
For Each b In a
If b = "甲" Then
If i = 1 Then
Set c = b
i = i + 1
End If
If i >= 2 Then
Set c = Excel.Application.Union(c, b)
End If
End If
Next
c.Select
c.Interior.Color = vbRed
Set a = Nothing
Set c = Nothing
Next
End Sub
运行vab时遇到的问题:
解决:
需加上下面这句话
Sheets(j).Select
原因:在当前的表没法select其他的表格,需要强调一下Range对象所在的工作表。
*vba小白学习第一天