Greetings,
I have a function which converts a column number reference to a letter reference. However, when I try to pass that converted column letter reference using
Columns("E:" & myCol).Select
or
Columns("E:" & myCol & "").Select
, I receive a "Run-time error '1004'." I've tested the function using:
Sub Test2()
MsgBox GetColumnLetter(100)
End Sub
and it correctly displays the column letter.
Below is my macro and function:
Sub Test1()
Dim lc As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("sheet1")
lc = ws.Cells(3, ws.Columns.count).End(xlToLeft).Column
myCol = GetColumnLetter(lc)
'Columns("E:" & myCol & "").Select
'Columns("E:" & myCol).Select
Selection.ClearFormats
End Sub
Function GetColumnLetter(colNum As Long) As String
'http://stackoverflow.com/questions/16941083/use-last-column-for-a-rangeflastcolumn
Dim vArr
vArr = Split(Cells(1, colNum).Address(True, False), "$")
GetColumnLetter = vArr(0)
End Function
Bookmarks