LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA get ColumnName

It's frustrating to get columnname from a label in Excel. So I strolled
through some user forums, looked at some code (read: copy & paste ;-)
and came up with this:

Function SplitString(s As String, del As String) As Variant
Dim a() As Variant
Dim i As Integer
Dim y As Integer
Dim sTemp As String
sTemp = s
i = 0
y = 0
Do
ReDim Preserve a(i)
y = InStr(sTemp, del)
a(i) = Left$(sTemp, y - 1)
i = i + 1
sTemp = Mid$(sTemp, y + 1)
Loop While InStr(y, sTemp, del) 0
ReDim Preserve a(i)
a(i) = sTemp
SplitString = a()
End Function

Function GetColumnNameFromLabel(label As String) As String
Dim i As Integer
Dim aArray As Variant
Dim CellAddress As String
Dim ColName As String

CellAddress = Range("ALLOWED_LENGTH").Address
aArray = SplitString(CellAddress, "$")
For i = 0 To UBound(aArray)
If i = 1 Then ColName = aArray(i)
Next
GetColumnNameFromLabel = aArray(1)
End Function

As an example for using this:
Dim ColName As String
ColName = GetColumnNameFromLabel("ALLOWED_LENGTH")
MsgBox ColName

Hope someone finds this as useful as I do.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"