Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function ColumnNumToColumnLetter(ColumnNum As Long) As String
- 'returns an excel column letter from a column number
- 'if the column letter cannot be determine returns vbNullString
- Dim regex As Object
- Dim matches As Object
- Dim addr As String
- Set regex = CreateObject("VBScript.RegExp")
- regex.Pattern = "[A-Z]+"
- addr = Cells(1, ColumnNum).Address(False, False)
- If regex.test(addr) Then
- Set matches = regex.Execute(addr)
- ColumnNumToColumnLetter = matches(0)
- Else
- ColumnNumToColumnLetter = vbNullString
- End If
- Set regex = Nothing
- Set matches = Nothing
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement