R1C1 lookup and variable incrementation

mmetzinger

Board Regular
Joined
Dec 30, 2010
Messages
61
Ok, I am trying to figure out how to increment a R1C1 reference. I am running this code through a loop so I have to move columns for each loop.

Here is an example of my attempted code

Code:
Dim ProductCol As Integer
ProductCol = 1

ActiveCell.FormulaR1C1 = "=Original!R[ProductCol]C & Original!RC[ProductCol]"

Excel doesn't like this code but for the life of me I can't figure out how to input the variable into the lookup formula.

Any ideas on how to use the variable in the lookup?

Thanks,
Matt
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You have to break up your "" "" to get the variables recognized, otherwise VBA interprets your entire command as one long string (ie it doesn't know that ProductCol is a variable)

ActiveCell.FormulaR1C1 = "=Original!R[" & ProductCol & "]C & Original!RC[" & ProductCol & "]"
 
Upvote 0
Thanks! How do you make it an absolute reference now? The column keeps changing on me as I move to the next cell to the right. I tried to remove the brackets but this only locked the cell not the column.



You have to break up your "" "" to get the variables recognized, otherwise VBA interprets your entire command as one long string (ie it doesn't know that ProductCol is a variable)

ActiveCell.FormulaR1C1 = "=Original!R[" & ProductCol & "]C & Original!RC[" & ProductCol & "]"
 
Upvote 0
If you want to hardcode the column then just put the column number right in to the formula instead of using ProductCol variable.

But I may not understand what you are trying to do. Can you post a bit more code?
 
Upvote 0
Not sure if this is the problem.... But..

I notice that you are using a variable called ProductCol in the ROW portion of the R1C1 reference.
The variable's name indicates to me that it is intended for use in the COLUMN section of the R1C1 reference...

Maybe I missed something though...
 
Upvote 0
Yep, that was the problem! I noticed it after staring for a while! My final code snippet for this piece is below:

Code:
ActiveCell.FormulaR1C1 = "=Original!R" & ProductRow & "C" & ProductCol & " & Original!RC" & ProductAttb & ""

Thanks for the help!

Matt


Not sure if this is the problem.... But..

I notice that you are using a variable called ProductCol in the ROW portion of the R1C1 reference.
The variable's name indicates to me that it is intended for use in the COLUMN section of the R1C1 reference...

Maybe I missed something though...
 
Upvote 0

Forum statistics

Threads
1,215,227
Messages
6,123,739
Members
449,116
Latest member
alexlomt

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