![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Posts: 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! |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
Use something like:
Where "A1:A14" is your target range and "A1" is the selected cell to copy from. HTH |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
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
__________________
Kind regards, Al Chara |
|
|
|
|
|
#4 |
|
New Member
Join Date: Apr 2002
Location: Chile
Posts: 3
|
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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|