Results 1 to 9 of 9

Saving of data into separate file using different choice and into different folder

Threaded View

  1. #2
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Saving of data into separate file using different choice and into different folder

    With extra sheet (Help)
    and for column C in sheet request only 1 letter

    Sub test()
    Dim lr As Long, arr As Variant, x As Long
    Application.ScreenUpdating = False
    With Sheets("Request")
        arr = .Range("A1", "C" & .Range("A" & .Rows.Count).End(xlUp).Row)
        For x = 1 To UBound(arr)
            If arr(x, 3) = "" Then arr(x, 3) = arr(x - 1, 3)
        Next
    End With
    Sheets("P").Range("A1").CurrentRegion.ClearContents
    Sheets("C").Range("A1").CurrentRegion.ClearContents
    Sheets("T").Range("A1").CurrentRegion.ClearContents
    With Sheets("Sheet1")
        colp = Application.Match("Product", .Range("1:1"), 0)
        colc = Application.Match("Customer Code", .Range("1:1"), 0)
        colt = Application.Match("Type", .Range("1:1"), 0)
        If .AutoFilterMode Then .AutoFilter.ShowAllData
        For x = 1 To UBound(arr)
            Select Case arr(x, 3)
                Case Is = "C"
                    .Range("A1").CurrentRegion.AutoFilter field:=colc, Criteria1:=arr(x, 1)
                    With .Range("A1").CurrentRegion
                        .Offset(1).Copy Sheets("Help").Range("A1")
                    End With
                    With Sheets("Help")
                        lr = .Range("A" & .Rows.Count).End(xlUp).Row
                        .Sort.SortFields.Add2 Key:=Range(Cells(1, colp), Cells(lr, colp)) _
                        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
                    End With
                    With Sheets("Help").Sort
                        .SetRange Range("A1").CurrentRegion
                        .Header = xlNo
                        .MatchCase = False
                        .Orientation = xlTopToBottom
                        .SortMethod = xlPinYin
                        .Apply
                    End With
                    Sheets("Help").Copy
                    ActiveWorkbook.SaveAs arr(x, 2) & "\" & Range("B1").Value & ".xlsx"
                    ActiveWorkbook.Close True
                    Sheets("Help").Range("A1").CurrentRegion.ClearContents
                Case Is = "P"
                    .Range("A1").CurrentRegion.AutoFilter field:=colp, Criteria1:=arr(x, 1)
                    With .Range("A1").CurrentRegion
                        .Offset(1).Copy Sheets("Help").Range("A1")
                    End With
                    With Sheets("Help")
                        lr = .Range("A" & .Rows.Count).End(xlUp).Row
                        .Sort.SortFields.Add2 Key:=Range(Cells(1, colc), Cells(lr, colc)) _
                        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
                    End With
                    With Sheets("Help").Sort
                        .SetRange Range("A1").CurrentRegion
                        .Header = xlNo
                        .MatchCase = False
                        .Orientation = xlTopToBottom
                        .SortMethod = xlPinYin
                        .Apply
                    End With
                    Sheets("Help").Copy
                    ActiveWorkbook.SaveAs arr(x, 2) & "\" & Range("A1").Value & ".xlsx"
                    ActiveWorkbook.Close True
                    Sheets("Help").Range("A1").CurrentRegion.ClearContents
                Case Is = "T"
                    .Range("A1").CurrentRegion.AutoFilter field:=colt, Criteria1:=arr(x, 1)
                    With .Range("A1").CurrentRegion
                        .Offset(1).Copy Sheets("Help").Range("A1")
                    End With
                    With Sheets("Help")
                        lr = .Range("A" & .Rows.Count).End(xlUp).Row
                        .Sort.SortFields.Add2 Key:=Range(Cells(1, colc), Cells(lr, colc)) _
                        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
                        .Sort.SortFields.Add2 Key:=Range(Cells(1, colp), Cells(lr, colp)) _
                        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
                    End With
                    With Sheets("Help").Sort
                        .SetRange Range("A1").CurrentRegion
                        .Header = xlNo
                        .MatchCase = False
                        .Orientation = xlTopToBottom
                        .SortMethod = xlPinYin
                        .Apply
                    End With
                    Sheets("Help").Copy
                    ActiveWorkbook.SaveAs arr(x, 2) & "\" & Range("C1").Value & ".xlsx"
                    ActiveWorkbook.Close True
                    Sheets("Help").Range("A1").CurrentRegion.ClearContents
            End Select
            .AutoFilter.ShowAllData
        Next
    End With
    End Sub
    Kind regards
    Leo
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Creating a folder and saving file within Folder (Naming convention within file)
    By alex900_6 in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 03-06-2021, 06:34 PM
  2. [SOLVED] Saving files from separate folders in folder, macro
    By Pi* in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-12-2018, 06:43 AM
  3. Master data should get in another sheet in separate file in a folder
    By santbiju1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-18-2015, 03:09 AM
  4. [SOLVED] Saving multiple file versions in the same folder if file already exists
    By lsargent in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-17-2015, 10:49 AM
  5. Need Save As script where user gets Drive/Folder choice but data establishes file name>
    By ILoveStMartin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-09-2013, 04:40 PM
  6. [SOLVED] Saving a file to new folder dependant on the first letter of the file name.
    By G_La_Mood in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2012, 10:58 AM
  7. Problem saving Excel file that copies an embedded object from a separate file
    By bhodge10 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-16-2012, 02:47 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