Continue Formula until certain cell reached

deduwa

Board Regular
Joined
Jul 28, 2015
Messages
110
Hi - I have the following code;


Dim lastRow As Long
lastRow = Cells(Rows.Count, "D").End(xlUp).Row

Range("X2:X" & lastRow).FormulaR1C1 = "=SUM(RC[-3]:RC[-1])"

Is there a way to amend or add to this code so that the SUM formula starts in row 2 of column X and continues down, but stops as soon as the data in column A reads 'Duplicate'

Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
How about
Code:
Sub Addsum()
   Dim fnd As Range
   
   Set fnd = Range("A:A").find("duplicate", , , xlWhole, , , False, , False)
   If fnd Is Nothing Then Exit Sub
   Range("X2:X" & fnd.Row).FormulaR1C1 = "=SUM(RC[-3]:RC[-1])"
End Sub
 
Upvote 0
Thanks Fluff - that works. Out of curiosity where are there so many commas after Find( ?
 
Upvote 0
It saves having to type in the Parameter names
 
Upvote 0
Thanks Fluff - that works. Out of curiosity where are there so many commas after Find( ?
The Find function has 9 arguments, the last 8 of them are optional. In order to specify some of the later arguments one needs to specify the argument prior to it. If you want to use what ever the default is for an optional argument, you simply do not put anything in the argument position reserved for it, hence, you will see two commas next to each other for that argument position.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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