Excel macro help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need help in creating a macro that will compare two columns of text.
Essentially, I need this macro to look at column A and for whatever column A
is, to look in column B for an expected answer. If the answer given isn't
part of the list of variables, I need a result screen.

So if in column A I have the word 'CAR', and the acceptable variables for
'CAR' are "red", "green" and "blue", but in Column B the result is "FORD", I
need to have that line highlighted. Sorry if this doesn't make a lot of
sense, too little sleep, too much tea!

Thanks,
Jean
 
Depends on setting up the Select case, you could do select Cases nested
instead of if statements. Depends on how complicated your data is in
actuality.
Sub RightInfo()
'Start in column "B" on the first data element to compare to
' "A", will run till it runs out of data
Do Until ActiveCell.Value = ""
BValue = ActiveCell.Value
AValue = ActiveCell.Offset(0, -1).Value
Select Case AValue
Case "Car"
If BValue = "Red" Or BValue = "Green" Then
'Do nothing
Else
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
Case Else

End Select
ActiveCell.Offset(1, 0).Select
Loop
End Sub

Hope this will help.
David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top