I have a table in excel where i am inserting some column, because of that last column is getting changed, I have to detect the last column and set it as a range in vba
I have written code to find the last column and convert it to alphabet, however i am not able to set it as a range.
Public Function ColumnLetter(ColumnNumber As Long) As String
ColumnLetter = Split(Cells(1, ColumnNumber).Address(True, False), "$")(0)
End Function
Dim Rng As Range
Dim LastColumn, LastRow As Long
Dim Str As String
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
LastColumn = Cells(2, Columns.Count).End(xlToLeft).Column
Str = ColumnLetter(LastColumn)
'Set Rng = Range("M7:M" & LastRow)
I want to write Commented line as
Set Rng = Range( & Str & "7" & LastRow)
To make it dynamic How can i do this?