+ Reply to Thread
Results 1 to 11 of 11

Creating 3 new sheets & then pull data from a file name to create a date

Hybrid View

  1. #1
    Registered User
    Join Date
    03-18-2011
    Location
    Dayton, ME, USA
    MS-Off Ver
    Excel 2004 for MAC 11.5.4
    Posts
    77

    Creating 3 new sheets & then pull data from a file name to create a date

    Hi

    I have just been given a problem that I know I need a macro to perform, but it is way above anything I have done before, so I am hoping that someone here can help.

    Attached is a sample file and also the ideal results file I would like to achieve through the Macro.

    In a nutshell this is what I want to do:

    1. Create a sheet that only has "approved" records in it shown in col U
    2. Create a sheet that only has "non approved" records in it also shown in col U (basically everything that is not approved)
    3. Create a Summary sheet for the "approved" records.

    With regards to the Summary Sheet:-

    Col A needs to total the values in Col A on the "Approved" Sheet
    Col B will always be GBP
    Col C needs to populate the date from either the file name, or from cell C1 on the "approved" sheet.
    Col D needs to find the day of the week based on the date shown in Col C.
    Col E needs to check the day shown in col D : If it is Sunday / Monday / Tuesday or Wednesday then the result should be Col C date + 3 days. If Thursday or Sat + 4 days, If Friday + 5 days.

    Really struggling to even see where to begin.

    Any and all help massively appreciated.

    Kind regards

    Jon
    Attached Files Attached Files
    Last edited by endoskeleton; 03-26-2011 at 02:27 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Creating 3 new sheets & then pull data from a file name to create a date

    Give this a try:
    Option Explicit
    
    Sub Reformat()
    Dim wsApp As Worksheet
    Dim wsNon As Worksheet
    Dim wsSum As Worksheet
    Dim LR    As Long
    
    Sheets(1).Copy Before:=Sheets(1)
    Sheets(1).Name = "Problem Files"
    Worksheets.Add(Before:=Sheets(1)).Name = "Approved"
    Worksheets.Add(Before:=Sheets(1)).Name = "Summary"
    Set wsNon = Sheets("Problem Files")
    Set wsApp = Sheets("Approved")
    Set wsSum = Sheets("Summary")
    
    With wsNon
        .Rows(2).AutoFilter
        .Rows(2).AutoFilter 21, "Approved"
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        If LR > 2 Then
            .Range("A2:A" & LR).EntireRow.Copy wsApp.Range("A1")
            .Range("A3:A" & LR).EntireRow.Delete xlShiftUp
        End If
        .AutoFilterMode = False
    End With
    
    With wsSum
        With .Range("A1:E1")
            .Value = [{"Amount","CurrencyCode","Processed Date","Processed Day","Release Date"}]
            .Font.Bold = True
            .HorizontalAlignment = xlCenter
            .Font.Size = 12
            .ColumnWidth = 14
        End With
        
        .Range("A2").FormulaR1C1 = "=SUM(Approved!C)"
        .Range("B2") = "GPD"
        .Range("C2").FormulaR1C1 = "=RIGHT('Problem Files'!R[-1]C,10)+0"
        .Range("C2,E2").NumberFormat = "mm/dd/yy;@"
        .Range("D2").FormulaR1C1 = "=RC[-1]"
        .Range("D2").NumberFormat = "dddd"
        .Range("E2").FormulaR1C1 = "=RC[-2]+ LOOKUP(WEEKDAY(RC[-2]),{1,5,6,7},{3,4,5,4})"
        .UsedRange.Value = .UsedRange.Value
        .Columns.AutoFit
        .UsedRange.HorizontalAlignment = xlCenter
    End With
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    03-18-2011
    Location
    Dayton, ME, USA
    MS-Off Ver
    Excel 2004 for MAC 11.5.4
    Posts
    77

    Re: Creating 3 new sheets & then pull data from a file name to create a date

    Wow,

    That is so good and so fast. Just blown away. Thank you so much !!

    Once tiny glitch is that on the "real" raw data sheet I just realized that there is a bottom row of data that I don't require, but as some of it is numerical it is effecting the summary total amount. Is there a way to get the macro to ignore that very bottom row of data in the raw data sheet ?

    Cheers

    Jon

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Creating 3 new sheets & then pull data from a file name to create a date

    That's weird, the only way that row at the bottom would get copied to the APPROVED sheet is if that row had the word "approved" in column U. Take that out if it does. The Summary sheet is only adding the column A from the APPROVED sheet, so I don't see how any rows that shouldn't be there would get onto that sheet.

  5. #5
    Registered User
    Join Date
    03-18-2011
    Location
    Dayton, ME, USA
    MS-Off Ver
    Excel 2004 for MAC 11.5.4
    Posts
    77

    Re: Creating 3 new sheets & then pull data from a file name to create a date

    Yeah, it was a odd chance occurance that in this string at the bottom it happened to have "Approved" in the right column to copy to the "Approved" sheet.

    Dont worry, I managed to cobble a fix together by asking the original sheet to search for the last cell in Column A (which is the one causing the problem) and then clearing that cell before it performs the adding sheets action. Works great now.

    Thanks so much for your help. I have learnt so much in the last week just by trying to decipher the code you produced.

    Cheers

    Jon

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Creating 3 new sheets & then pull data from a file name to create a date

    Glad to help.

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  7. #7
    Registered User
    Join Date
    03-18-2011
    Location
    Dayton, ME, USA
    MS-Off Ver
    Excel 2004 for MAC 11.5.4
    Posts
    77

    Re: Creating 3 new sheets & then pull data from a file name to create a date

    Hi

    I just found a small issue with the code, which I am sure I can sort out myself, I just need clarification on one part:-

    .Range("E2").FormulaR1C1 = "=RC[-2]+ LOOKUP(WEEKDAY(RC[-2]),{1,5,6,7},{3,4,5,4})
    If I am reading this correctly it is saying if the cell is showing day 1 (presumably Monday) the populate as day 3 (presumably Wednesday).

    Is that correct ? If so it will help me a lot with the tweaking.

    Thanks

    Jon

  8. #8
    Registered User
    Join Date
    03-18-2011
    Location
    Dayton, ME, USA
    MS-Off Ver
    Excel 2004 for MAC 11.5.4
    Posts
    77

    Re: Creating 3 new sheets & then pull data from a file name to create a date

    Never mind, I had an hour to play around with those numbers and it became obvious that 1 = sunday and that the second set of numbers relates to the number of days increase required.

    Thanks so much for your help

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Creating 3 new sheets & then pull data from a file name to create a date

    There you go...

  10. #10
    Registered User
    Join Date
    03-18-2011
    Location
    Dayton, ME, USA
    MS-Off Ver
    Excel 2004 for MAC 11.5.4
    Posts
    77

    Re: Creating 3 new sheets & then pull data from a file name to create a date

    Thanks so much for all of your help with this code, it has saved such a huge amount of time.

    I wanted to ask if there is a way to create a code that would be able to create a master summary workbook.

    Basically I would have worksheets created each day by running the macro (above) providing a summary sheet of the data from that day.

    I would like to be able to have a new master workbook that looks at the folder where these files are stored recognizes when a new file has been generated and then copies the data from that summary sheet and pastes that data as new line in the Master Summary worksheet.

    I had found some code to open newest files in a folder, but there maybe times (after a weekend) when I could have 3 days files generated and put into the folder on a Monday, so this code would only pick up the most recent. Which is why I thought a search for un-inputted files would work better.

    Would appreciate you having a look.

    Many thanks

    Jon

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Creating 3 new sheets & then pull data from a file name to create a date

    Jon, this thread/question has been resolved. Please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

    Then post your new question in a new thread, you will garner the most attention from new eyes, and it's the rules.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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