VBA Trend function with variable rows

uti1301

New Member
Joined
Jul 17, 2017
Messages
18
I have 17 columns A to R.
I want to use the TREND function to enter values in column R, starting at row 3.

I have the following code successfully for rows 3 to 39:

sub test()
dim lastforecastmonth as long
lastforecastmonth=cells(rows.count, "A").end(xlup).row
range("R").select
for I=0 to lastforecastmonth-3
activecell.formulaR1C1= "=trend(R3C2:R39C2, R3C5:R39C17, RC[-13]:RC[-17]"
next I
end sub

My problem is that the number of rows can vary.

I would be very grateful if someone could tell me how to do this

Thanks in advance for any help
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
sorry, line 6 of code should be:
activecell.offset(I,0).formulaR1C1= "trend(R3C2:R39C2, R3C5:R39C17, RC[-13]:RC[-17])"
 
Upvote 0
sorry again, line 6 of code should be:
activecell.offset(I,0).formulaR1C1= "=trend(R3C2:R39C2, R3C5:R39C17, RC[-13]:RC[-1])"
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
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