vba macro

Bob Clausen

New Member
Feb 12, 2010
I have a workbook with 31 worksheets.
One worksheet for everyday of the month.
They are named 1,2,3,...29,30,31
I am having trouble writing a macro to do the following.
In Range("k16") is a value on each worksheet.
On the worksheet #2 i want to average the value of k16 of the first and second sheet.
On the worksheet #3 i want to average the value of k16 of the first, second, third worksheet. I hope you follow my logic.
Of course I don't want to average all worksheets until that day has come to the corresponding worksheet.
I want to put the average for day 1 & 2 on the second worksheet in let's say Range("k17").
Getting caught up in opening sheets or correct order.
Thankyou, Bob


Well-known Member
Sep 24, 2009
Sub daysAvg()
Dim currDay As Integer
currDay = Day(Date)
For i = 2 To currDay
    Sheets("" & i).Select
    Sheets("" & i).Range("K17") = (Sheets("" & (i - 1)).Range("K16") * (i - 1) + Sheets("" & i).Range("K16")) / i
Next i
End Sub
Try This


Well-known Member
Jan 26, 2005
This is also possible using only formulas, although it's ugly.

Basically, you can use the fact that this formula gives you the name of the current worksheet as a number:


And this one tells you what's in the previous sheet's cell K17:


Oh, and this gives you the number of the current day:


Combine things in the same way nightcrawler did in his code and voila! Easy as pie. :)

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...