Excel VBA formula

syoun02

New Member
Joined
Apr 18, 2002
Messages
23
I am just learning VBA for excel. I have a formula that I am having repeat numerous times. In this formula I am subtracting 2 cells. How do I preserve the formula while allowing it to change to the next row? If you look below, I am asking how to change "b5-C5" to "b6-C6" and so on as the code repeats.

Selection.Offset(0, 2).Formula = "=B5-C5"


Thanks!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Use something like:

<pre>
Selection.AutoFill Destination:=Range("A1:A14"), Type:=xlFillDefault</pre>

Where "A1:A14" is your target range and "A1" is the selected cell to copy from.

HTH
 
Upvote 0
Do you want something like this:

For i = 5 To 6
Selection.Offset(i - 5, 2).Formula = "=" & Cells(i, 2).Address(rowabsolute:=False, columnabsolute:=False) _
& "-" & Cells(i, 3).Address(rowabsolute:=False, columnabsolute:=False)
Next i
 
Upvote 0
I have the same problem, but it is in a search of a range I specify (a2:a10) and that it looks (search) for the content of a cell specifies (b2) and it replaces by the content of a cell specifies (c2).
¿How I make to change the values of the cells (b2, c2) to (b3, c3) to (b4,c4)etc ?
please help
thanks
Pedro
 
Upvote 0

Forum statistics

Threads
1,214,402
Messages
6,119,304
Members
448,886
Latest member
GBCTeacher

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