modifying columns in vlookups easily

bigdan

Well-known Member
Joined
Oct 5, 2009
Messages
846
Office Version
  1. 2013
Platform
  1. Windows
I just had to set up a vlookup formula for Jan to Dec. Was kinda annoying changing the numbers for each month, like writing vlookup(A1,B100:M200,1,false) and changing the 1 to 2 to 3 etc.


I realize we can create a helper row with 1-12 hidden somewhere and link the 1 in the formula to that instead. I dont mind doing that temporarily but I would like those numbers to get embedded in.

Is there a way to do this?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try this:

=VLOOKUP(A1,B100:M200,TEXT(NOW(),"m"),FALSE)

It will use the number of the current month.
 
Upvote 0
Are you copying the formula down a column or across a row?

What is the cell address of the first cell that contains the formula?
 
Upvote 0
I'm copying from left to right. The first cell would be B1.
 
Upvote 0
If this isn't what you are looking for:

=VLOOKUP(A1,$B$100:$M$200,TEXT(NOW(),"m"),FALSE)

try this:

=VLOOKUP(A1,$B$100:$M$200,column()-1,FALSE)

The column()-1 statement is returning the column number of the column the cell is in (B=2) and taking 1 from it. When you drag this across and down, the result of that statement will increase by 1 each column you go across. Hope this makes sense!
 
Last edited:
Upvote 0
I'm a big fan of using Index/Match in this situation.
Givin this example vlookup from the original post
vlookup(A1,B100:M200,1,false)

Try
=INDEX(B$1:B$100,MATCH($A1,$B$1:$B$100,0))

Drag it to the right.
 
Upvote 0
=VLOOKUP(A1,$B$100:$M$200,column()-1,FALSE)
That doesn't work if I enter the formula in cell GH27! ;)

Using COLUMN()-1 is dependent upon the cell the formula is entered in.

Using the COLUMNS(...) and/or ROWS(...) functions are more robust.
 
Last edited:
Upvote 0
That doesn't work if I enter the formula in cell GH27! ;)

I know how it works and I explained it at the bottom of that post:

The column()-1 statement is returning the column number of the column the cell is in (B=2) and taking 1 from it. When you drag this across and down, the result of that statement will increase by 1 each column you go across. Hope this makes sense!

In this case, we know that the formula will be put into B1 and copied across and down.

It's one perfectly valid way of doing it. There are many!
 
Last edited:
Upvote 0
In this case, we know that the formula will be put into B1 and copied across and down.

I think that even knowing the formula will be put in column B it is recommended and more robust to use COLS($B1:B1)
Why? Suppose that, for some reason, a new column is inserted to the left of column B.

M.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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