[VBA] How to split data into multiple workbooks & retain the format

zeromax1

Board Regular
Joined
Mar 20, 2020
Messages
52
Office Version
  1. 365
Platform
  1. Windows
Hello everyone. I would like to ask for your help. I want to split the data into multiple workbooks by PIC. (please see the following cap screen) It means each file contains the unique data of each PIC. The format also will be kept for each new workbook. The new workbook name will be the "origin file name - (PIC)" and place at the same path of the origin file.

Besides that, the whole page of "Code Table" will be copy to these new workbook at the same time.

Please download my demo: Trail Split Sheet2.xlsx

The format should be kept in each new workbook. "
1584687510358.png


I have already refer to this post (VBA Split One Worksheet Into Multiple Workbooks and Retain Formatting) and try to modify the code by myself. Unfortunately, the code only applicable to the Column A with number.
 
Last edited by a moderator:
It's the fileformat number specifying to save as an xlsx file.

Hello Fluff, Are there possible to add one more column for the criteria?
Eg. I want to split the files base on Column A & B.

I attached my VBA code:

VBA Code:
Sub Split()
   Dim cl As Range
   Dim WS As Worksheet
   Dim rng As Range
    
   Application.ScreenUpdating = False
  
   Set WS = ThisWorkbook.Worksheets(1)
   Filename = ThisWorkbook.Name
   If InStr(Filename, ".") > 0 Then
        Filename = Left(Filename, InStr(Filename, ".") - 1)
    End If
    
   If WS.FilterMode Then WS.ShowAllData
   With CreateObject("scripting.dictionary")
      For Each cl In WS.Range("A9", WS.Range("A" & Rows.Count).End(xlUp))
         If Not .Exists(cl.Value) Then
            .Add cl.Value, Nothing
            WS.Copy
            Range("A8").AutoFilter 1, "<>" & cl.Value
            Range("A9:A3000").SpecialCells(xlVisible).EntireRow.Delete
            ActiveSheet.ShowAllData
            ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & Filename & " " & "(" & cl.Value & ")" & ".xlsx", 51
            ActiveWorkbook.Close False
         End If
        
                
      Next cl

   End With
End Sub
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Can you please start a new thread for this, thanks.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top