Sub Change_Format()
Dim Row1 as Integer
Row1 = 4
Do While Cells(Row1, 2) <> ""
If Cells(Row1, 2).ColorIndex = 255 Or Cells(Row1, 2).ColorIndex = 5287936 Then
Range.(Cells(Row1, 5), Cells(Row1, 6),Cells(Row1, 7)).Select
Selection.FormatConditions.Delete
End If
Loop
End Sub
我在选择行中的第5,6和7列时遇到了麻烦,我到处搜索所以我认为没有办法做到这一点,如果你知道怎么告诉我,你们是我最后的希望。
Sub Change_Format()
Dim Row1 As Integer
Row1 = 4
Do While Cells(Row1, 2) <> ""
If Cells(Row1, 1) = "OK" Then
Cells(Row1, 5).Resize(, 3).Select
Selection.FormatConditions.Delete
End If
Row1 = Row1 + 1
Loop
End Sub
大家好,这是我现在使用的代码,工作得很好,我只是好奇一件事,如果我想选择跳跃列,例如同一行和第4,6和8列。选择
很抱歉再次打扰并感谢您的帮助。
正如我在评论中所说,你可能只想要.Resize
Sub Change_Format()
Dim Row1 As Integer
Row1 = 4
Do While Cells(Row1, 2) <> ""
If Cells(Row1, 2).ColorIndex = 255 Or Cells(Row1, 2).ColorIndex = 5287936 Then
Cells(Row1, 5).Resize(,3).Select 'Select 3 columns to the right
Selection.FormatConditions.Delete
End If
Loop
End Sub
下面是一个简单子例程的示例,它选择行/列右侧的3列:
Sub Select3Columns(TheRow As Long, TheColumn As Variant)
Cells(TheRow, TheColumn).Resize(, 3).Select
End Sub
Select3Columns 5,"A"
的结果: