I have an excel spreadsheet with a title row at the top. I am trying to log the column number of each cell in the top row of my excel spreadsheet (title row) that matches a certain string such as "Recommended Action 1"
For Each c In Worksheets("Cost Estimates").Range(Cells(1, 1), Cells(totalRows, totalCols))
If c.Value = "Recommended Action 1" Then
recAct1 = c.Column
Debug.Print CStr(recAct1)
ElseIf c.Value = "Recommended Action 2" Then
recAct2 = c.Column
ElseIf c.Value = "Recommended Action 3" Then
recAct3 = c.Column
End If
Next
Where recAct holds the column number and totalRows and totalCols are the total number of rows and columns (respectively on the spreadsheet).
I keep receiving a 'Type Mismatch' error for:
If c.Value = "Recommended Action 1" Then
I put my cursor over the c value during this error and I get an 'Error 2023' message.
I suspected that it was because c was a column number and not an actual range address. I think this error is caused by the fact that I do not know what type of variable 'c' is actually returning -- I thought it was a range object.
Recommended Action 1
,Recommended Action 2
andRecommended Action 3
? – Siddharth RoutError 2023
is a#Ref!
error. TryIf CStr(c.Value)...
– David Zemens