If statement or Lookup on a range

RightCoastRipper

New Member
Joined
Mar 25, 2011
Messages
4
Hi

I am trying to run an if statement on a range of cells to obtain a corresponding set of values in a separate range (i would be fine with overwrite the original range too)

For every cell1 in range(C2:J50)
If cell1 = 1 then cell2 = 50, If cell1 = 2 then cell2=20....If cell1 = 10 then cell2=1, Else 'do nothing, endif
Loop

cell2 is in range(N2:W50)

The if statement can also be phrased as a lookup in excel:

N2=VLOOKUP(C2, $AA$2:$AB$11, 2, 1)
For every cell in range(N2:W50)

Where AA2:AA11 is a column 1,2,..,10 and AB2:AB11 is a column of the corresponding values.

Can you please help me make this work in a macro???
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Welcome to the forums!

Why do you need this to be in a macro? Are you needing the macro to create the VLOOKUP formula, or do you need it to create the value?
 
Upvote 0
This line of code should do it for you:

Code:
Range("N2:W50").Formula = "=VLOOKUP(C2,$AA$2:$AB$11,2,1)"
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

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