INDIRECT Function use in VBA

alexf972

New Member
Joined
May 21, 2012
Messages
27
I am trying to implement INDIRECT function in VBA, while using variables, but I am doing it wrong. Could anyone please tell me how the code should be written? In the following example I am trying to read the value from cell A1:

Dim xxx as Integer
xxx = 1
ActiveCell.FormulaR1C1 = "=INDIRECT(""A" & xxx")"


Thanks in advance!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
the code above (when corrected) posts the formula indirect(A1) into cell a1. what exactly are you trying to achieve. You say trying to read the value of a1 but to do what with it?
 
Upvote 0
You don't need FormulaR1C1 since your formula is in A1 notations, so just use Formula. In addition, you use of quote marks is incorrect. Here is how that line of code should be written...

ActiveCell.Formula = "=INDIRECT(""A" & xxx & """)"
 
Upvote 0
Solution
the code above (when corrected) posts the formula indirect(A1) into cell a1. what exactly are you trying to achieve. You say trying to read the value of a1 but to do what with it?
I am reading various cells using Indirect and a variable, but this is only a part of the code I've been struggling with
 
Upvote 0
You don't need FormulaR1C1 since your formula is in A1 notations, so just use Formula. In addition, you use of quote marks is incorrect. Here is how that line of code should be written...

ActiveCell.Formula = "=INDIRECT(""A" & xxx & """)"
Thank you! That works perfectly fine!
 
Upvote 0

Forum statistics

Threads
1,213,556
Messages
6,114,284
Members
448,562
Latest member
Flashbond

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