+ Reply to Thread
Results 1 to 66 of 66

Need VBA to create new Workbook and name it based on cell value in original file

Hybrid View

YukonSoDank Need VBA to create new... 04-07-2019, 03:40 PM
Mumps1 Re: Need VBA to create new... 04-07-2019, 04:09 PM
YukonSoDank Re: Need VBA to create new... 04-07-2019, 04:21 PM
YukonSoDank Re: Need VBA to create new... 04-07-2019, 04:36 PM
Mumps1 Re: Need VBA to create new... 04-07-2019, 04:44 PM
YukonSoDank Re: Need VBA to create new... 04-07-2019, 05:01 PM
Mumps1 Re: Need VBA to create new... 04-09-2019, 09:28 AM
YukonSoDank Re: Need VBA to create new... 04-09-2019, 12:30 PM
Mumps1 Re: Need VBA to create new... 04-09-2019, 12:38 PM
YukonSoDank Re: Need VBA to create new... 04-09-2019, 01:03 PM
Mumps1 Re: Need VBA to create new... 04-09-2019, 01:07 PM
YukonSoDank Re: Need VBA to create new... 04-09-2019, 02:32 PM
YukonSoDank Re: Need VBA to create new... 04-09-2019, 07:54 PM
Mumps1 Re: Need VBA to create new... 04-10-2019, 10:32 AM
YukonSoDank Re: Need VBA to create new... 04-13-2019, 11:28 AM
Mumps1 Re: Need VBA to create new... 04-13-2019, 03:10 PM
YukonSoDank Re: Need VBA to create new... 05-08-2019, 07:37 AM
Mumps1 Re: Need VBA to create new... 05-08-2019, 09:12 AM
YukonSoDank Re: Need VBA to create new... 05-08-2019, 09:29 AM
Mumps1 Re: Need VBA to create new... 05-08-2019, 09:56 AM
YukonSoDank Re: Need VBA to create new... 05-08-2019, 10:07 AM
Mumps1 Re: Need VBA to create new... 05-08-2019, 10:16 AM
YukonSoDank Re: Need VBA to create new... 05-08-2019, 10:23 AM
Mumps1 Re: Need VBA to create new... 05-08-2019, 10:32 AM
YukonSoDank Re: Need VBA to create new... 05-08-2019, 01:09 PM
Mumps1 Re: Need VBA to create new... 05-08-2019, 03:10 PM
YukonSoDank Re: Need VBA to create new... 05-08-2019, 03:13 PM
Mumps1 Re: Need VBA to create new... 05-08-2019, 03:20 PM
YukonSoDank Re: Need VBA to create new... 05-08-2019, 08:31 PM
Mumps1 Re: Need VBA to create new... 05-09-2019, 08:13 AM
YukonSoDank Re: Need VBA to create new... 05-09-2019, 11:24 AM
Mumps1 Re: Need VBA to create new... 05-09-2019, 11:35 AM
YukonSoDank Re: Need VBA to create new... 05-09-2019, 08:59 PM
Mumps1 Re: Need VBA to create new... 05-10-2019, 08:32 AM
YukonSoDank Re: Need VBA to create new... 05-10-2019, 09:13 AM
Mumps1 Re: Need VBA to create new... 05-10-2019, 01:22 PM
YukonSoDank Re: Need VBA to create new... 05-13-2019, 07:25 PM
Mumps1 Re: Need VBA to create new... 05-14-2019, 10:11 AM
YukonSoDank Re: Need VBA to create new... 05-14-2019, 09:13 PM
Mumps1 Re: Need VBA to create new... 05-15-2019, 11:07 AM
YukonSoDank Re: Need VBA to create new... 05-30-2019, 10:24 AM
Mumps1 Re: Need VBA to create new... 05-30-2019, 11:43 AM
YukonSoDank Re: Need VBA to create new... 05-30-2019, 12:34 PM
Mumps1 Re: Need VBA to create new... 05-30-2019, 01:06 PM
YukonSoDank Re: Need VBA to create new... 05-30-2019, 01:44 PM
Mumps1 Re: Need VBA to create new... 05-31-2019, 09:37 AM
YukonSoDank Re: Need VBA to create new... 05-31-2019, 09:45 AM
Mumps1 Re: Need VBA to create new... 05-31-2019, 11:39 AM
YukonSoDank Re: Need VBA to create new... 05-31-2019, 01:15 PM
Mumps1 Re: Need VBA to create new... 05-31-2019, 02:25 PM
YukonSoDank Re: Need VBA to create new... 05-31-2019, 02:53 PM
Mumps1 Re: Need VBA to create new... 06-01-2019, 12:33 PM
YukonSoDank Re: Need VBA to create new... 06-01-2019, 03:28 PM
Mumps1 Re: Need VBA to create new... 06-02-2019, 07:49 AM
YukonSoDank Re: Need VBA to create new... 06-02-2019, 09:23 AM
Mumps1 Re: Need VBA to create new... 06-03-2019, 09:59 AM
YukonSoDank Re: Need VBA to create new... 06-08-2019, 02:47 PM
  1. #1
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need VBA to create new Workbook and name it based on cell value in original file

    In the attached, the one macro in the file (view macros obvi) sums all the lines across any tab with a "*_CF" name into the orange "Summary_Cash_Flow" tab.

    This works great, but while each of the *_CF tabs will have identical layouts and row names, the dates at the top will likely vary.

    That said I would like the macro to match the proper date with the proper amount, realizing I likely have to expand the date range at the top of the Summary tab to accommodate this function.

    To jog your memory (understood there's been so many iterations), the code below was used to crawl across files that were stored in a folder to perform a similar summation, the difference this time around is the tabs are all contained in one file and landing area is the same size as the source area.

    So really the bold portion was the magic behind this one:


    Sub updateTotals()
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
        Dim wkbSource As Workbook, sPath As String
        Dim lCol As Long, desWs As Worksheet, srcWS As Worksheet, fDateCol As Long, x As Long, y As Long, strdate As String
        y = 4
        Set desWs = ThisWorkbook.Sheets("Summary")
        desWs.Range("D5:PW14").ClearContents
        'Const strPath As String = "C:\Project Models\"
        Const strPath As String = "C:\Forum Help\Yukon\"
        ChDir strPath
        strExtension = Dir(strPath & "*.xlsx")
        Do While strExtension <> ""
            Set wkbSource = Workbooks.Open(strPath & strExtension)
            Set srcWS = Sheets("Monthly Cash Flow")
            With srcWS
                .Range("B1").Formula = "=TEXT(LEFT(D2,FIND(""/"",TEXT(D2,""mm/dd/yyyy""),4)),""mm/dd/yy"")"
                strdate = .Range("B1")
                lCol = desWs.Cells(1, desWs.Columns.Count).End(xlToLeft).Column - 1
                fDateCol = desWs.Rows(2).Find(Format(.Range("B1").Value2, "m/dd/yy"), LookIn:=xlValues, lookat:=xlWhole).Column
                With desWs
                    .Cells(5, fDateCol) = .Cells(5, fDateCol) + srcWS.Cells(5, 3) + srcWS.Cells(5, 4)
                    .Cells(6, fDateCol) = .Cells(6, fDateCol) + srcWS.Cells(6, 3) + srcWS.Cells(6, 4)
                    .Cells(7, fDateCol) = .Cells(7, fDateCol) + srcWS.Cells(7, 3) + srcWS.Cells(7, 4)
                    .Cells(8, fDateCol) = .Cells(8, fDateCol) + srcWS.Cells(8, 3) + srcWS.Cells(8, 4)
                    
                    
                End With
                For x = fDateCol + 1 To lCol
                    With desWs
                        On Error Resume Next
                        .Cells(5, x) = .Cells(5, x) + srcWS.Cells(5, y)
                        .Cells(6, x) = .Cells(6, x) + srcWS.Cells(6, y)
                        .Cells(7, x) = .Cells(7, x) + srcWS.Cells(7, y)
                        .Cells(8, x) = .Cells(8, x) + srcWS.Cells(8, y)
                        
                      
                        y = y + 1
                    End With
                Next x
            End With
            y = 4
            wkbSource.Close False
            strExtension = Dir
        Loop
        Application.Calculation = xlCalculationAutomatic
        Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: Need VBA to create new Workbook and name it based on cell value in original file

    Thank you for uploading. When I looked at the _CF sheets, I noticed that some of the dates in C2 of those sheets don't exist in the Summary_Cash_Flow sheet. Am I missing something?
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

+ 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. Replies: 5
    Last Post: 10-17-2018, 02:35 AM
  2. [SOLVED] Need to modify macro to also create backup of original file
    By tfilipe in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-15-2018, 03:25 PM
  3. open worksheet in a different workbook based on cell name in original workbook
    By thara95 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-03-2017, 07:38 AM
  4. VBA that works perfectly in one file errors out in a new file based off the original!
    By carthesis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-09-2016, 07:24 AM
  5. Replies: 1
    Last Post: 07-17-2014, 12:06 PM
  6. Splitting Excel file but want to create data links to original
    By hitchy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-10-2013, 11:46 AM
  7. Trying to create a 2nd workbook to mirror the first, to protect the original
    By zachdking in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-06-2013, 08:11 PM

Tags for this Thread

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