Nov 22 2022 08:51 AM - edited Nov 22 2022 08:53 AM
Hi,
I would like to be assisted with a vba code/macro to accomplish below. I have attached a sample workbook.
1. The macro to hide all blanks rows ( deselect hyphen only) under " Description" and loop through the next worksheets
2. Then the macro to prompt where to save the file e.g. Documents and use the name on cell K11 as the name of the file.
Nov 22 2022 01:22 PM
Do you want to save each sheet separately?
Nov 22 2022 02:50 PM
SolutionAssuming that you want to save each sheet separately:
Sub HideAndSave()
Dim wb As Workbook
Dim ws As Worksheet
Dim f As Variant
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = ActiveWorkbook
For Each ws In wb.Worksheets
ws.Range("B14").AutoFilter Field:=1, Criteria1:="<>-"
ws.Copy
Application.Dialogs(xlDialogSaveAs).Show ws.Range("K11").Value & ".xlsx"
ActiveWorkbook.Close SaveChanges:=False
Next ws
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Nov 22 2022 09:29 PM
Nov 22 2022 10:24 PM
Nov 23 2022 03:29 AM
Here you go.
Sub HideAndSave()
Dim wb As Workbook
Dim ws As Worksheet
Dim fp As String
With Application.FileDialog(4) ' msoFileDialogFolderPicker
If .Show Then
fp = .SelectedItems(1)
If Right(fp, 1) <> "\" Then
fp = fp & "\"
End If
Else
Beep
Exit Sub
End If
End With
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = ActiveWorkbook
For Each ws In wb.Worksheets
ws.Range("B14").AutoFilter Field:=1, Criteria1:="<>-"
ws.Copy
ActiveWorkbook.SaveAs Filename:=fp & ws.Range("K11").Value & ".xlsx"
ActiveWorkbook.Close SaveChanges:=False
Next ws
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub