UsedRange method to find the last used column number in a worksheet


Sub LastUsedColumn_UsedRange_1()

Dim lastColumn As Integer

lastColumn = ActiveSheet.UsedRange.Column - 1 + ActiveSheet.UsedRange.Columns.Count

MsgBox lastColumn

End Sub



Sub LastUsedColumn_UsedRange_2()

Dim lastColumn As Integer

lastColumn = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column

MsgBox lastColumn

End Sub

Comments

Popular posts from this blog

50 Excel VBA Oral Interview Questions