我是VBA的新手(有点),我被分配了一个繁琐的任务,即搜索超过5000行,根据单元格值突出显示行(从A到j,colorindex = 6)并且它是'我永远带我基本上我正在尝试开发一个程序来搜索C列下的字符串,如果单元格等于搜索的字符串,则从活动单元格偏移到下面的4行,对于任何大于37的数字,它会停止找到一个索引颜色为33的行中的单元格。任何想法?我开始了,现在卡住了。任何想法都会有所帮助谢谢
Sub Priority()
'Declaring all worksheets in the excel file
Dim US As Worksheet
Dim Venr50 As Worksheet
Dim Priority As Worksheet
Dim CBT As String
'setting all variables declared
Set US = Worksheets("US CKS")
Set Venr = Worksheets("VENR50 US 09.24")
Set Priority = Worksheets("Priority")
CBT = Priority.Range("$C$6").Value
With US
Dim x As Long
For x = 4 To 3000
If Cells(x, "C").Value = CBT Then
ActiveCell.Interior.ColorIndex = 33
ActiveCell.Offset(4, 0).Select
End If
答案 0 :(得分:0)
您可以在For循环中执行另一个循环,如下所示:
Dim x As Long
Dim j as integer
For x = 4 To 3000
If Cells(x, "C").Value = CBT Then
For j=1 to 4
If Cells(x+j,"C").Value>37 then Cells(x+j,"C").ColorIndex = 6
If Cells(x+j,"C").Interior.ColorIndex = 33 then exit sub
Next j
End If
If Cells(x+j,"C").Interior.ColorIndex = 33 Then Exit Sub
Next x
编辑: 要更改多行的颜色索引,您可以使用:
Range(Cells(x+j,"A"),Cells(x+j,"J")).Interior.ColorIndex = 6