# Excel formula to VBA code

#### PaulCL

##### New Member
Hello Folks,
Can anyone convert this excel formula to VBA.

=IF(ISNA(VLOOKUP(A2,'Original BHHS List'!\$A\$1:\$A\$84,1,FALSE)), "Not Duplicate", "Duplicate")

Tks

### Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

#### Trebor76

##### Well-known Member
This will put the formula into cell A1 of the active sheet (change to suit):

Code:
``````Option Explicit
Sub Macro1()

Range("A1").Formula = "=IF(ISNA(VLOOKUP(A2,'Original BHHS List'!\$A\$1:\$A\$84,1,FALSE)), ""Not Duplicate"", ""Duplicate"")"

End Sub``````

Regards,

Robert

#### PaulCL

##### New Member
Works perfectly. Thanks

You're welcome

#### PaulCL

##### New Member
Range("B2").Formula = "=IF(ISNA(VLOOKUP(A2,'Original BHHS Error List'!\$A\$1:\$A\$84,1,FALSE)), ""New Error"", ""Duplicate Error"")"

What would be the code to have the result of the formula in "B2" filldown as far as there is data in column A
Tks

#### Trebor76

##### Well-known Member
Try this:

Code:
``Range("B2:B" & Cells(Rows.Count, "A").End(xlUp).Row).Formula = "=IF(ISNA(VLOOKUP(A2,'Original BHHS Error List'!\$A\$1:\$A\$84,1,FALSE)), ""New Error"", ""Duplicate Error"")"``

Robert

#### PaulCL

##### New Member
Works! Thanks again!!

Replies
17
Views
534
Replies
12
Views
439
Replies
1
Views
677
Replies
3
Views
625
Replies
0
Views
818

1,195,704
Messages
6,011,206
Members
441,594
Latest member
AVO

### 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.

### Which adblocker are you using?

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

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