Combine vlookup and if functions in VBA

Urner

New Member
Joined
Sep 3, 2011
Messages
10
Here's what I've been trying to do for the last hour without any particular success:

I want to write a macro that will do exactly the same thing written below

IF result for vlookup(Range1,Range2,2,False) is blank THEN write down the word "COW" ELSE write the result of that vlookup.

Take into consideration that vlookup is not for a single cell but an entire column. Thus, I want to put "COW" only in the cells where vlookup returns no value (that is 0 or blank).


How I'm supposed to do it?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try
=IF(ISNA(VLOOKUP($A11,L21:Q36,2,FALSE)),"COW",IF(VLOOKUP($A11,L21:Q36,2,FALSE)=0,"COW",IF(TRIM(VLOOKUP($A11,L21:Q36,2,FALSE))="","COW",VLOOKUP($A11,L21:Q36,2,FALSE))))

$A11 is the lookup value (you can't use a range here) but you can drag is down a column of values
$L$21:$Q$36 is the range to lookup where the corresponding Key to A11 is in L21 to L36 (the first column)
 
Upvote 0
Thanks Chuckie, great answer. You are correct. However, the database I want this formula for is large and by saying large I mean that it is so big that pasting a formula for each cell will make the computer unresponsive for the entire day.

That's why I'd like to do it with macros to spare time and the computer.

Does anyone know how to do it?
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,551
Members
452,927
Latest member
rows and columns

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