By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

expertatexcel.com

 


FindDataCol("fieldname",row_nbr) udf

🔝Used to find a fields column in a spreadsheet and remove hardcoding


Function FindDataCol(SearchValue, r As Long, Optional report As Boolean) As Long
'Version: 1.000
'Purpose: Finds SearchValue in row r
Dim c As Long, curcol As Long

c = FindLastCol(r)
curcol = 0
For curcol = c To 1 Step -1
    If IsError(Cells(r, curcol)) Then
        GoTo next_for
    End If

    If Trim(Cells(r, curcol)) = Trim(SearchValue) Then
        FindDataCol = curcol
        Exit Function
    End If
  
next_for:
Next
FindDataCol = 0
If report Then
    MsgBox "Can't find " & SearchValue & " in row " & r & " on sheet " & ActiveSheet.Name
End If


End Function