VLOOKUP with IF function

BBCC0000

New Member
Joined
Nov 2, 2022
Messages
32
Office Version
  1. 365
Platform
  1. Windows
Hi all 🥹,

May I know how do I create a macro that applies to Column H, starts from H2 to the last value with the following criteria:-

It will VLOOKUP from cell G2 to the last,
1) If the value of G2 equals to the Column A, it will show TRUE with Green highlight;
2) If the value of G2 equals to the Column D, it will show FALSE with Red highlight;
3) If the value of G2 doesn't equal to Column A and D, it will show CHECK with Yellow highlight.

Can refer to the image for reference.

1711529252827.png



Thank you for reading my query! Hope you can help me on solving this macro. 😆
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try :
Excel Formula:
=IF(COUNTIF(A:A,G2),"TRUE",IF(COUNTIF(D:D,G2),"FALSE","CHECK"))
 
Upvote 0
how do I create a macro that applies to Column H, starts from H2 to the last value with the following criteria:-
Give this a try with a copy of your workbook.

VBA Code:
Sub CorrectWrong()
  Dim i As Long
  
  With Range("H2:H" & Range("G" & Rows.Count).End(xlUp).Row)
    .Formula2 = "=IF(ISNUMBER(MATCH(G2,A:A,0)),""TRUE"",IF(ISNUMBER(MATCH(G2,D:D,0)),""FALSE"",""CHECK""))"
    .Value = .Value
    For i = 1 To .Rows.Count
      Select Case .Cells(i).Text
        Case "TRUE": .Cells(i).Interior.Color = vbGreen
        Case "FALSE": .Cells(i).Interior.Color = vbRed
        Case Else: .Cells(i).Interior.Color = vbYellow
      End Select
    Next i
  End With
End Sub
 
Upvote 0
Give this a try with a copy of your workbook.

VBA Code:
Sub CorrectWrong()
  Dim i As Long
 
  With Range("H2:H" & Range("G" & Rows.Count).End(xlUp).Row)
    .Formula2 = "=IF(ISNUMBER(MATCH(G2,A:A,0)),""TRUE"",IF(ISNUMBER(MATCH(G2,D:D,0)),""FALSE"",""CHECK""))"
    .Value = .Value
    For i = 1 To .Rows.Count
      Select Case .Cells(i).Text
        Case "TRUE": .Cells(i).Interior.Color = vbGreen
        Case "FALSE": .Cells(i).Interior.Color = vbRed
        Case Else: .Cells(i).Interior.Color = vbYellow
      End Select
    Next i
  End With
End Sub

Thanks for your reply. I encountered this error when I execute the code:

1711589077415.png


It stuck at this row:
.Formula2 = "=IF(ISNUMBER(MATCH(G2,A:A,0)),""TRUE"",IF(ISNUMBER(MATCH(G2,D:D,0)),""FALSE"",""CHECK""))"


Is it the version issue?
 
Upvote 0
Your profile says you have MS365, are you running it on a MS365 machine ?
That formula doesn't actually need Formula2.
Try changing it to just Formula and see if that fixes it.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,215
Members
453,024
Latest member
Wingit77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top