Reputation: 21
How can I modify my code to select the rows until column L instead of the entire row?
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
Upvotes: 2
Views: 172
Reputation:
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.
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
Upvotes: 1