Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |