futureexcelguru
New Member
- Joined
- Jan 25, 2022
- Messages
- 3
- Office Version
- 2019
- Platform
- Windows
Hi all! I'm needing some help updating an existing code to paste the data into my new sheet hopefully including formulas, data validation, and conditional formatting. Relatively new to VBA and had some help creating the below, so any help is appreciated!
Its set up to create a new sheet based on text in Column B:B on the Q3-Q4 worksheet. For example, Column B has 5 text options (Test 1, Test 2, Test 3, Test 4, Test5) across 5000 rows. The new workbooks created from the below code will create 5 workbooks to a specified folder path per B text with all the data/rows applicable, its just pasting values and i'm losing most of the formatting formulas. *It is pasting the fill/text colors and borders that populated from the conditional formatting entered on the main workbook
Code here:
Option Explicit
Sub Split_Data_in_workbooks()
Application.ScreenUpdating = False
Dim data_sh As Worksheet
Set data_sh = ThisWorkbook.Sheets("Q3-Q4")
Dim setting_Sh As Worksheet
Set setting_Sh = ThisWorkbook.Sheets("Settings")
Dim nwb As Workbook
Dim nsh As Worksheet
setting_Sh.Range("A:A").Clear
data_sh.AutoFilterMode = False
data_sh.Range("B:B").Copy setting_Sh.Range("A1")
setting_Sh.Range("A:A").RemoveDuplicates 1, xlYes
Dim i As Integer
For i = 2 To Application.CountA(setting_Sh.Range("A:A"))
data_sh.UsedRange.AutoFilter 2, setting_Sh.Range("A" & i).Value
Set nwb = Workbooks.Add
Set nsh = nwb.Sheets(1)
data_sh.UsedRange.SpecialCells(xlCellTypeVisible).Copy nsh.Range("A1")
nsh.UsedRange.EntireColumn.ColumnWidth = 15
nwb.SaveAs setting_Sh.Range("H6").Value & "/" & setting_Sh.Range("A" & i).Value & ".xlsx"
nwb.Close False
data_sh.AutoFilterMode = False
Next i
setting_Sh.Range("A:A").Clear
MsgBox "Done"
End Sub
Its set up to create a new sheet based on text in Column B:B on the Q3-Q4 worksheet. For example, Column B has 5 text options (Test 1, Test 2, Test 3, Test 4, Test5) across 5000 rows. The new workbooks created from the below code will create 5 workbooks to a specified folder path per B text with all the data/rows applicable, its just pasting values and i'm losing most of the formatting formulas. *It is pasting the fill/text colors and borders that populated from the conditional formatting entered on the main workbook
Code here:
Option Explicit
Sub Split_Data_in_workbooks()
Application.ScreenUpdating = False
Dim data_sh As Worksheet
Set data_sh = ThisWorkbook.Sheets("Q3-Q4")
Dim setting_Sh As Worksheet
Set setting_Sh = ThisWorkbook.Sheets("Settings")
Dim nwb As Workbook
Dim nsh As Worksheet
setting_Sh.Range("A:A").Clear
data_sh.AutoFilterMode = False
data_sh.Range("B:B").Copy setting_Sh.Range("A1")
setting_Sh.Range("A:A").RemoveDuplicates 1, xlYes
Dim i As Integer
For i = 2 To Application.CountA(setting_Sh.Range("A:A"))
data_sh.UsedRange.AutoFilter 2, setting_Sh.Range("A" & i).Value
Set nwb = Workbooks.Add
Set nsh = nwb.Sheets(1)
data_sh.UsedRange.SpecialCells(xlCellTypeVisible).Copy nsh.Range("A1")
nsh.UsedRange.EntireColumn.ColumnWidth = 15
nwb.SaveAs setting_Sh.Range("H6").Value & "/" & setting_Sh.Range("A" & i).Value & ".xlsx"
nwb.Close False
data_sh.AutoFilterMode = False
Next i
setting_Sh.Range("A:A").Clear
MsgBox "Done"
End Sub