VBA - posting a formula to use the next row

Evapar18

Board Regular
Joined
Aug 3, 2018
Messages
86
Office Version
  1. 2019
Platform
  1. Windows
I hope this makes sense. I am want to be able to copy a formula to a cell, but I need it to use the next row number.

See below:
If TextBox1 = Enabled And TextBox2 = Enabled Then

With Sheets("Sheet1")

rw = .Range("B" & .Rows.Count).End(xlUp).Row + 1

.Range("P" & rw).Value = TextBox1
.Range("Q" & rw).Value = TextBox2
.Range("E" & rw).Value = "=C9-P9"
.Range("F" & rw).Value = "=C9-Q9"

End With

The Column won't change, but the row number will change. How can I copy this simple formula to use the active row this is copied too?

Thanks,
SB
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Do you mean you want the row number in the formula to be the same as the row number the formula is going in?

e.g. if it was going in row 10 the first formula would be =C10-P10?

Code:
With Sheets("Sheet1")

    rw = .Range("B" & .Rows.Count).End(xlUp).Row + 1

    .Range("P" & rw).Value = TextBox1
    .Range("Q" & rw).Value = TextBox2
    .Range("E" & rw).FormulaR1C1 = "=RC[-2]-RC[11]"
    .Range("F" & rw).FormulaR1C1 = "=RC[-3]-RC[11]"

End With
 
Upvote 0
You could use this to replace both lines:

Code:
.Range(.Cells(rw, "E"), .Cells(rw, "F")).FormulaR1C1 = "=RC3-RC[11]"
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,167
Members
452,615
Latest member
bogeys2birdies

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