Row reference in my VBA code

gabe

New Member
Joined
Jul 30, 2008
Messages
33
I wrote some VBA code that checks for a couple different variables and if the code passes then a formula is pasted into a specific location into my spreadsheet.

The formula is as follows:

=10^($AN19*LOG10($K19)+$AO19-$AP19*0.6745)

What's happening is that the formula is being pasted in my cell exactly as written above (row and column reference as-is). What I really want is for the column references to be locked (as noted) but the row reference to change based on the row where my formula ends up. It could be anywhere from row 1 to row 1000. How do I change the formula to allow the row reference to change based on the row where my formula is inserted into my spreadsheet?

Thanks,
Gabe
 
How about providing your current code so we can take a look how you're deducing which row to put the formula into? (Remember to use CODE tags!)
 
Upvote 0
How about setting a variable to your row reference:

Cells(i, "B").Formula = "=10^($AN" & i & "*LOG10($K" & i & ")+$AO" & i & "-$AP" & i & "*0.6745) "

HTH
 
Upvote 0
I was at home last night and didn't have access to my spreadsheet with the actual code. Below is the code right before the formula that I wanted to insert into my spreadsheet. Again, the column references will always stay the same but I want the row references to change based on the row where the formula is inserted.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Range(Lname.Name).Offset(LlngOutRow, 0).Formula = "=10^(AJ15*LOG10(G15*1000)+AK15-AL15*0.6745)/1000"
 
Upvote 0
Hi

One way

Code:
Dim r As Range
 
' ...
 
Set r = Range(Lname.Name).Offset(LlngOutRow, 0)
r.Formula = "=10^(AJ" & r.Row & "*LOG10(G" & r.Row & "*1000)+AK" & r.Row & "-AL" & r.Row & "*0.6745)/1000"

or use thr R1C1 notation:

Code:
Range(Lname.Name).Offset(LlngOutRow, 0).FormulaR1C1 = "=10^(RC36*LOG10(RC7*1000)+RC37-RC38*0.6745)/1000"

In this case the the column references are absolute.
 
Upvote 0

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