As always, it got to 17.00 and I clicked something and lost a working Macro that I now cannot replicate.
I am trying to write a macro for a series of spreadsheets where the column I wish to average (same in each) has varying numbers of rows.
As a very amateur VBA writer, I managed to record a Macro and edit the values (xlDown) so it that looked at a larger range depending on how many rows in the data.
The whole macro converts dates stored as text to numerical value, then copy and pastes it to 'dd/mm/yy hh/mm/ss' then averages associated data in a column F.
The section of macro I broke was along the lines of:
"Range("F2").Select
ActiveCell.FormulaR1C1 = "=AVERAGE(RC[-2]:R[End(xlDown)]C[-2])"
Range("F2").Select
ActiveWindow.SmallScroll Down:=-18"
I cannot remember exactly what I put in as the R[End(xlDown)] part but it worked once and now cannot replicate... I am trying to enter in cell F2 the average of column D from D2 to the end of the column.
Any ideas?
Many thanks in advance.
Damien
Last edited by damo_uk; 01-16-2012 at 01:17 PM. Reason: SOLVED
You can assign a variable to the lastrow of column D ...for example -You do not require the Select statements and even the scroll down statements.dim lrow as long lrow=range("D" & rows.count).end(xlup).row range("F2").formulaR1C1 = "=AVERAGE(RC[-2]:R[" & lrow & "]C[-2])"
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
Thank you very much Arlette.
Answered my query perfectly![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks