突出显示行直到特定列

时间:2022-02-22 21:24:19

How can I modify my code to select the rows until column L instead of the entire row?

如何修改我的代码以选择行直到列L而不是整行?

Sub trial()

小试()

Dim c As Range
Dim rngG As Range
For Each c In Intersect(ActiveSheet.UsedRange, Columns("f"))
    If c >= 1 Then

        If rngG Is Nothing Then Set rngG = c.EntireRow
        Set rngG = Union(rngG, c.EntireRow)
    End If
Next c
rngG.Select

End Sub

结束子

1 个解决方案

#1


1  

Just add an intersect to,

只需添加一个相交,

    If rngG Is Nothing Then Set rngG = c.EntireRow
    Set rngG = Union(rngG, c.EntireRow)

... like,

... 喜欢,

    If rngG Is Nothing Then Set rngG = intersect(range("A:L").entirecolumn, c.EntireRow)
    Set rngG = Union(rngG, intersect(range("A:L").entirecolumn, c.EntireRow))

TBH, I'm not sure if .entirecolumn is completely necessary but I ran into this issue a while back and adding .entirecolumn was the fix.

TBH,我不确定.entirecolumn是否完全是必要的,但我在一段时间后遇到了这个问题并添加.entirecolumn就是修复。

Dim c As Range, rngG As Range

For Each c In Intersect(ActiveSheet.UsedRange, Columns("f"))
    If c >= 1 Then
        If rngG Is Nothing Then Set rngG = intersect(range("A:L").entirecolumn, c.EntireRow)
        Set rngG = Union(rngG, intersect(range("A:L").entirecolumn, c.EntireRow))
    End If
Next c
rngG.Select

#1


1  

Just add an intersect to,

只需添加一个相交,

    If rngG Is Nothing Then Set rngG = c.EntireRow
    Set rngG = Union(rngG, c.EntireRow)

... like,

... 喜欢,

    If rngG Is Nothing Then Set rngG = intersect(range("A:L").entirecolumn, c.EntireRow)
    Set rngG = Union(rngG, intersect(range("A:L").entirecolumn, c.EntireRow))

TBH, I'm not sure if .entirecolumn is completely necessary but I ran into this issue a while back and adding .entirecolumn was the fix.

TBH,我不确定.entirecolumn是否完全是必要的,但我在一段时间后遇到了这个问题并添加.entirecolumn就是修复。

Dim c As Range, rngG As Range

For Each c In Intersect(ActiveSheet.UsedRange, Columns("f"))
    If c >= 1 Then
        If rngG Is Nothing Then Set rngG = intersect(range("A:L").entirecolumn, c.EntireRow)
        Set rngG = Union(rngG, intersect(range("A:L").entirecolumn, c.EntireRow))
    End If
Next c
rngG.Select