+ Reply to Thread
Results 1 to 2 of 2

macro to autopopulate dat + copy over template worksheet with formulas

  1. #1
    Registered User
    Join Date
    12-31-2017
    Location
    UK
    MS-Off Ver
    7
    Posts
    42

    macro to autopopulate dat + copy over template worksheet with formulas

    Hi All, i'm using the macro below to auto populate worksheets with incrementing date it is also copying the first sheet as a template into the other sheets. The one problem is that the templates being copied don't contain the formulas from the original sheet, and there is also one formula in particular which is pulling data from the previous sheet. This formula is:

    =IF(D8="","","PSC-"&VLOOKUP(D8,Names!$A$1:$C$39,2,FALSE)&"-"&TEXT(VLOOKUP(D8,Names!$A$1:$C$39,3,FALSE)+COUNTIF(E$7:E7,"PSC-"&VLOOKUP(D8,Names!$A$1:$C$39,2,FALSE)&"-*")+COUNTIF(Sheet1!$E$8:$E$27,"PSC-"&VLOOKUP(D8,Names!$A$1:$C$39,2,FALSE)&"-*")+COUNTIF(Sheet2!$E$8:$E$27,"PSC-"&VLOOKUP(D8,Names!$A$1:$C$39,2,FALSE)&"-*"),"0000"))

    here you can see countif sheet1! then countif sheet2! With the marco i have created sheets for 6months, so don't want to keep copying this formula in the next worksheet and manually typing in the next sheet number i.e COUNTIF(Sheet3!$E$8:$E$27,"PSCCROY-"&VLOOKUP(D9,Names!$A$1:$C$39,2,FALSE)&"-*")

    The other formulas in the worksheet are basic so don't look up previous sheets etc, but would like these in the copied over as well as the above issue.

    macro:

    Sub Dtpopulate()

    Dim newname As String
    Dim dte As Long
    Dim Names As Worksheet

    Set Names = ThisWorkbook.Worksheets("Names") 'variable Names now represents
    'the Temp sheet.
    Application.ScreenUpdating = False

    Worksheets("Template").Cells().Copy 'copy whole Template sheet to clipboard

    'Names.Range("endDate") is the range named "endDate" on the Temp sheet
    'likewise for startDate

    For dte = Names.Range("endDate") To Names.Range("startDate") Step -1
    'dte is dateSerial (daynumber counting from 1-1-1900)

    newname = WorksheetFunction.Text(dte, "dd-mmm-yy")
    Sheets.Add.Name = newname 'Sheets.add returns a worksheet object
    'of which property name is set
    'it is inserted before the active sheet.

    With Sheets(newname).Cells 'paste from clipboard to all cells in new sheet

    .PasteSpecial Paste:=xlPasteValuesAndNumberFormats, _
    Operation:=xlNone, SkipBlanks:=False, Transpose:=False

    .PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    End With

    Next dte
    Application.ScreenUpdating = True

    End Sub



    Thanks in advance for your help

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: macro to autopopulate dat + copy over template worksheet with formulas

    Add code like this:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] using a macro to copy a worksheet but change formulas cell references
    By Jamidd1 in forum Excel Programming / VBA / Macros
    Replies: 28
    Last Post: 02-17-2016, 02:31 PM
  2. [SOLVED] Autopopulate macro, needs to searrch for appropriate section to autopopulate
    By Butcher1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-09-2015, 09:11 AM
  3. [SOLVED] Copy formulas from the Source worksheet to the Target worksheet using a macro
    By Excel987 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-10-2015, 04:03 PM
  4. [SOLVED] exporting data from master file to template file (autopopulate a template)
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-06-2014, 11:41 AM
  5. Macro - Copy worksheet template based on value
    By sbernardefc in forum Excel General
    Replies: 0
    Last Post: 09-06-2013, 06:19 AM
  6. Replies: 3
    Last Post: 05-15-2013, 11:34 PM
  7. [SOLVED] Need a Macro to Copy Worksheet template into the same workbook
    By justinprime in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-11-2012, 02:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1