Murray Brown
asked on
Excel VBA Find Lowest Column number in any range selection
Hi. I was given the following code by expert SubodH to find the highest column in any range selection.How would I adjust the code to find the lowest column number?
Sub LastCellInSelection()
Dim Rng As Range, Cell As Range, Col As Long
If Selection.Areas.Count = 1 Then
MsgBox "Last Column : " & ActiveCell.Offset(Selection.Rows.Count - 1, Selection.Columns.Count - 1).Column
MsgBox "Cell Address : " & ActiveCell.Offset(Selection.Rows.Count - 1, Selection.Columns.Count - 1).Address(0, 0)
Else
For Each Rng In Selection.Areas
If Rng.Column > Col Then
Col = Rng.Column
Set Cell = Rng.Cells(1).Offset(Rng.Rows.Count - 1)
End If
Next Rng
MsgBox Cell.Column
MsgBox Cell.Address(0, 0)
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome again! Happy to help.
ASKER
Hi. I asked a further question on finding the first row number https://www.experts-exchange.com/questions/29003615/Excel-VBA-Find-Lowest-Row-number-in-any-selection.html
Already responded there.
ASKER