Using wildcards in VBA - is this possible?

SNA400

Board Regular
Joined
Nov 5, 2010
Messages
52
Hi All,

I don't use VBA much in my current job, so i'm a bit rusty ;)

I am trying to get this line to work

Range("AM2", "AM" & llastrow).FormulaR1C1 = "=IFERROR(IF(RC[-2]=""Y"",VLOOKUP(2,DOC_CODE,4),""""),""P"")"

Where the "Y" is a 4 digit entry - i.e. Y923 or Y926 etc, but have tried a wildcard * with no luck.

Whats the best way to do this? The codes are always 1 alpha 3 numeric.

Simon
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi, here's one way you could consider.

Rich (BB code):
Range("AM2", "AM" & llastrow).FormulaR1C1 = "=IFERROR(IF(LEFT(RC[-2],1)=""Y"",VLOOKUP(2,DOC_CODE,4),""""),""P"")"
 
Upvote 0
HI FormR

Thanks for that -the Left works to allow the Y, but it doesn't bring up the data in column 4 for the Y code used...

I'm really trying to get it to look up whatever is entered and then display the corresponding info.
does that make sense?

Simon
 
Upvote 0
Looking again now the VLOOKUP() part of your formula doesn't look right at all, but without knowing anything about your set-up and what it is you are actually trying to lookup and where it is, it's difficult to comment further.

You could try to get the formula working on the sheet first before you try and incorporate it in the VBA.

If you can't figure it out and need more help then you'll need to share a more detailed explanation. Posting some sample data with the XL2BB tool that shows your expected results would also be of great help.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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