如何修改代码以选择直到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
结束子
答案 0 :(得分:1)
只需添加一个相交,
If rngG Is Nothing Then Set rngG = c.EntireRow
Set rngG = Union(rngG, c.EntireRow)
...喜欢,
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,我不确定.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