Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

That did the trick! Thank you very much. I appreciate the help
You're welcome again! Happy to help.
Already responded there.