You can put this macro into a standard code module (Insert > Module).
Then connect all your buttons on each of the sheets to the same macro, it will work for each and name each CSV for the same name as the sheet from which it is triggered.
Option Explicit
Sub ExportToCSV()
Dim fPATH As String, fNAME As String, LR As Long
fNAME = ActiveSheet.Name
fPATH = ThisWorkbook.Path & Application.PathSeparator
Application.ScreenUpdating = False
With ActiveSheet
.AutoFilterMode = False
.Rows("5:5").AutoFilter Field:=1, Criteria1:="<>"
LR = .Range("A" & .Rows.Count).End(xlUp).Row
If LR > 5 Then
.Range("A5:F" & LR).Copy
Sheets.Add
Range("A1").PasteSpecial xlPasteAll
ActiveSheet.Move
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs fPATH & fNAME & ".csv", FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close False
MsgBox "Export file done: " & fPATH & fNAME & ".csv"
Else
MsgBox "No rows with data found to export"
End If
.AutoFilterMode = False
End With
Application.ScreenUpdating = True
End Sub
Bookmarks