Save extracted files in current directory and more.

allanjones863

New Member
Joined
Feb 10, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I need the code below to save as an xlsb file in the current directory (same as original file), also need to be able to select the column to create workbooks (set as column 4 below), need input dialog to select which column. Further would like the new file to filtered.

Thank You




Sub PrepareFiles()
Dim DistDic As Object
Set DistDic = CreateObject("Scripting.Dictionary")
Dim WkRg As Range, Rg As Range
Dim K
Dim WkP As String
Application.ScreenUpdating = False
WkP = ActiveWorkbook.Path
Set WkRg = ActiveSheet.UsedRange
ActiveSheet.AutoFilterMode = False
For Each Rg In WkRg.Columns(4).Cells.Offset(1)
If (Rg <> "") Then DistDic.Item(Rg.Value) = Empty
Next Rg
For Each K In DistDic.keys
With WkRg
.AutoFilter Field:=4, Criteria1:=K
End With
Workbooks.Add
WkRg.SpecialCells(xlCellTypeVisible).Copy Destination:=Cells(1, 1)
Cells.EntireColumn.AutoFit
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=Fpath & "\" & FName & ".xlsb", FileFormat:=50
Application.DisplayAlerts = True
ActiveWorkbook.Close
Next K
ActiveSheet.AutoFilterMode = False
Application.ScreenUpdating = True
MsgBox ("Job Done")
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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