You are here:

Excel/Automating Excel Workbook - Update Summary Sheet



I am working on automating an Excel workbook to set up a year's worth of weekly hours.  I have the macro to create the new worksheets and name them properly.  I need the total fields on the new worksheets to populate back to the summary sheet (called Home in my macro below# which is the first sheet in the workbook.  Each successive week's total hours go in the cell immediately below the previous week's total hours.  The week's hours are grouped by Hours #straight time#, overtime, and vacation, so three cells from the week worksheet need to go back onto the summary sheet.  Here is what I have so far.  I think I am close, but I am not sure.

Sub sheetsWithDates##
'start with a workbook with a HOME sheet as the first sheet and the first week as the second sheet,
'with the first date in first week in cell A3
  Dim wksFrom As Worksheet, wksTo As Worksheet, wksHome As Worksheet
  Dim dateCell As Range
  Dim iWeek As Long, iSheetCount As Long
  Dim weekCount As Long
  Set wksFrom = ThisWorkbook.Sheets#2#
  Set dateCell = wksFrom.Range#"a3")
  Set wksHome = ThisWorkbook.Sheets(1)
  If Not IsDate(dateCell) Then Exit Sub
  wksFrom.Name = Format(wksFrom.Range("a9"), "mmmm dd, yyyy")
  For iWeek = 1 To 52
      iSheetCount = ThisWorkbook.Sheets.Count
      weekCount = iWeek
      wksFrom.Copy after:=ThisWorkbook.Sheets(iSheetCount)
      Set wksTo = ThisWorkbook.Sheets(iSheetCount + 1)
      wksTo.Range("a3") = wksFrom.Range("a3") + (7 * iWeek)
      wksTo.Name = Format(wksTo.Range("a9"), "mmmm dd, yyyy")
      wksHome.Range(Cells(30 + weekCount, 4)) = wksTo.Range("c11")
      wksHome.Range(Cells(30 + weekCount, 5)) = wksTo.Range("c12")
      wksHome.Range(Cells(30 + weekCount, 6)) = wksTo.Range("c13")
      Next iWeek
End Sub

Thanks for your help.  I will email the file to the email address you have on your website.

Thank you!

I would not use a macro for that, I would use INDIRECT() formulas in the original sheet that draws back the answers from those non-existent sheets.  By using INDIRECT(), we can piece those sheet/cell references together from strings, then draw back the answer if the sheet exists, or trap the error if the sheet does not exist yet.

Based on your example workbook, with the DATE that is eventually to be a the name of the sheet to draw data back from:

D30:  =IFERROR(INDIRECT("'" & TEXT($C30, "MMM DD, YYYY") & "'!C14"), "-")

E30:  =IFERROR(INDIRECT("'" & TEXT($C30, "MMM DD, YYYY") & "'!C12"), "-")

F30:  =IFERROR(INDIRECT("'" & TEXT($C30, "MMM DD, YYYY") & "'!C13"), "-")

...copied down.
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Jerry Beaucaire


Excel Formulas, macros, automation. Microsoft Excel MVP - 2010. Code site with free code snippets and techniques:


Microsoft Excel MVP - 2010. I have my own extensive Excel help/code site: ===================== I have been offering free assistance as an Excel aid on many web sites for many years: ( - JBeaucaire) ======== ( - JBeaucaire) ======= ( - jbeaucaire)

Bachelor's Degree from Azusa Pacific University in Mathematics and Music Composition

Awards and Honors
Microsoft Excel MVP 2010

©2017 All rights reserved.