Reputation: 37
I have around 20 columns in excel. I have to check the values in each cell in first row to match certain strings. For example A1 = “first” , B1 = “second” etc.. If the values don’t match my desired fixed string values, the messagebox should throw error with the column name and value. Can someone please help?
I am trying to match the row in bold with the values in would enter (highlighted in red, i dont have these in excel). If they dont match, i want the column name to pop up in message box.
Upvotes: 0
Views: 283
Reputation: 37
i have tried something like this
Dim a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, aa, ab, ac As String
If Trim(range("A1").Value) <> "name" Then a = " Header for Column A is incorrect "
If Trim(range("B1").Value) <> "type" Then a = " Header for Column B is incorrect "
MsgBox (" The following error(s) have occured " & vbCrLf & vbCrLf & a & b)
i guess i figured it out. thx
Upvotes: 0
Reputation: 103
Your question was not very clear and I am unable to post ‘comments’ yet/still.
Just shooting in the dark here, but something along these lines maybe? This is not tested and is not complete code, but should get you going farther than what you presented already.
LastRow = Sheets("SheetName").Range("A" & Rows.Count).End(xlUp).Row: x = 1
For Each c1 In Sheets("SheetName").Range("A1:A" & LastRow)
If c1.Value = "first"
x = x + 1
msgbox, “This is a message”
End If
Next c1
Upvotes: 1