+ Reply to Thread
Results 1 to 4 of 4

Macro saving files incorrectly

  1. #1
    Registered User
    Join Date
    12-06-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2010
    Posts
    71

    Macro saving files incorrectly

    With help from the community I have the below (and attached) macro, but still have a slight problem with it that I can't find in the code. It is saving each group with the improper name, i.e. the file name indicating Group 'AP' has data for Group 'CFO' and 'CFO' has the data for Group 'CA' etc.

    Sub SaveGroupFiles()
    Dim x As Long
    Dim stFolder As String, stFName As String
    stFolder = ActiveWorkbook.Path
    Range("Data").AdvancedFilter Action:=xlFilterCopy, copytorange:=Range("lst_group"), unique:=True
    Application.DisplayAlerts = False
    For x = 1 To Range("lst_group").Cells(1, 2)
    stFName = Range("Crit").Cells(2, 1) & Format(Date, "mmddyyyy") & Format(Time, "hhmm")
    Range("crit").Cells(2, 1) = Range("lst_group").Cells(x + 1, 1)
    Range("Data").AdvancedFilter Action:=xlFilterCopy, copytorange:=Range("dataout"), criteriarange:=Range("crit")
    Sheet3.Copy
    ActiveWorkbook.SaveAs Filename:=stFolder & "\" & stFName
    ActiveWorkbook.Close
    Next x
    End Sub


    Thanks in advance for the help.

    Copy of general 2015 percentages (3).xlsm

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Macro saving files incorrectly

    Hi there,

    Try the following code and see if it does what you need:

    Please Login or Register  to view this content.

    The basic problem was that the highlighted statement must be executed BEFORE a value is assigned to the variable "stFName".


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    12-06-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2010
    Posts
    71

    Re: Macro saving files incorrectly

    That was it, thank you very much!

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Macro saving files incorrectly

    Hi again,

    Many thanks for your prompt feedback - glad I was able to help.

    Regards,

    Greg M

+ 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. Saving macro created files in variable location.
    By richankur in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2015, 09:26 AM
  2. Overwrites old files when saving with macro, fix for this? Excel 2010
    By accelgronvall in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-12-2014, 08:06 AM
  3. Saving macro files
    By Macro_ in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-09-2014, 12:32 PM
  4. Macro for saving files every time worksheet is updated
    By superchew in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-02-2013, 03:06 PM
  5. Saving Multiple Files Using a Macro
    By Bpitman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-07-2012, 05:33 AM
  6. Saving Excel Files to Correct Format with Macro
    By Smurlos in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-09-2010, 06:49 PM
  7. [SOLVED] Excel 2000 worksheets save incorrectly as notepad files.
    By Capdu in forum Excel General
    Replies: 2
    Last Post: 04-02-2005, 11:06 AM

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