Using INDIRECT Function in VBA

eoinymc

Board Regular
Joined
Jan 29, 2009
Messages
203
Hi,

I have the following function in my workbook:
Code:
=INDIRECT("'Sheet 1'!J"&$N$1)

Cell N1 has the number of the row that the data is on that I want to display.

My issue is that the Column "J" is dynamic on a monthly basis.

So, I was trying to do something like this in VBA ( I have a lot of code that splits data and does a lot of calculations and data manipulation, so this would just be an extension of the code):

Code:
CurrMth = 10

Ind.Range("H3").FormulaR1C1 = "=INDIRECT("'Sheet 1'!" & [B]CurrMth [/B]& "&$N$1)"

But it obviously won't work..

Any ideas on how I can make this indirect function dynamic?

Cheers,

Eoin
 
Hi,

I have the following function in my workbook:
Code:
=INDIRECT("'Sheet 1'!J"&$N$1)

Cell N1 has the number of the row that the data is on that I want to display.

My issue is that the Column "J" is dynamic on a monthly basis.

So, I was trying to do something like this in VBA ( I have a lot of code that splits data and does a lot of calculations and data manipulation, so this would just be an extension of the code):

Code:
CurrMth = 10

Ind.Range("H3").FormulaR1C1 = "=INDIRECT("'Sheet 1'!" & [B]CurrMth [/B]& "&$N$1)"

But it obviously won't work..

Any ideas on how I can make this indirect function dynamic?

Cheers,

Eoin

I think the indirect function cannot be used in VBA. When you type Worksheetfuntion. it does not appear in the list.

You can use a mixed method:

1. Use the work sheet to define dinamically the range

InCell M15:
=ADDRESS(ROW(),3) &":"&ADDRESS(ROW()+$N$4-1,3+$N$4-1)

<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>
</tbody>
2. Get the address in VBA
MCorr = Range("Aux!M15")
Selection.FormulaArray = _
"=MCholesky(" & MCorr & ")"

<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,216,773
Messages
6,132,633
Members
449,740
Latest member
tinkdrummer

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