在同一行中选择不同的列

时间:2017-12-18 17:21:46

标签: vba select

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列,我在任何地方都搜索过,所以我觉得没有办法做到这一点,如果你们知道请告诉我,你们是我最后的希望。 / p>

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列。选择

很抱歉再次打扰并感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

正如我在评论中所说,你可能只想要.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"的结果:

Results

相关问题