Dynamically build call reference

UHsoccer

Well-known Member
Joined
Apr 3, 2002
Messages
1,023
I need to dynamically change the cell reference based on the month of the year that is being requested

Example
Range("G9").Select (is for Dec)
Range("I9").Select (is for Jan)

I need to do something like

if month = "Dec" then var = "G"
if month = "Jan" then var = "I"

How do I use "var" in the Range statement
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

bjwillingham

Active Member
Joined
Jun 17, 2003
Messages
287
Just a word of advice. I would not recomend hard coding a range address reference in a macro. If you ever move formulas or insert colums or rows the macro will mess you up big time.

I would suggets naming the top cell and then using offset references from the name. The name will move if rows or columns are inserted and the macro will continue to perform as expected.


"Think Ahead, Be Prepared"
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,096
Messages
5,768,064
Members
425,451
Latest member
JohnBrooksBiddle

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
Top