jeremypyle
Board Regular
- Joined
- May 30, 2011
- Messages
- 174
Hi
I have a macro that is saving sheets within my excel document as seperate csv files. However if the sheets have the filter command then this doesn't work. Is there a way to make this work saving on the visible values from the filter as csv?
Sub SaveFiles1()
Dim ShtGroup() As String
Dim Lr As Long, ws As Worksheet
Dim ShtName As String, c As Range
Dim n As Long
Lr = Sheets("Person Paying").Range("B" & Rows.Count).End(xlUp).Row
For Each c In Sheets("Person Paying").Range("B1:b" & Lr)
ShtName = c.Value & " IRD"
On Error Resume Next
Set ws = Sheets(ShtName)
On Error GoTo 0
If Not ws Is Nothing Then
n = n + 1
ReDim Preserve ShtGroup(1 To n)
ShtGroup = ShtName
End If
Set ws = Nothing
Next
For Each ws In Sheets(ShtGroup)
If ws.Range("A1") <> "" Then
ws.Copy
xcsvFile = "C:\OneDrive\Houses\Business\Wages\CSV\IRD" & "\ird_" & ws.Name & ".csv"
Application.ActiveWorkbook.SaveAs Filename:=xcsvFile, _
FileFormat:=xlCSV, CreateBackup:=False
Application.ActiveWorkbook.Saved = True
Application.ActiveWorkbook.Close
End If
Next
End Sub
I have a macro that is saving sheets within my excel document as seperate csv files. However if the sheets have the filter command then this doesn't work. Is there a way to make this work saving on the visible values from the filter as csv?
Sub SaveFiles1()
Dim ShtGroup() As String
Dim Lr As Long, ws As Worksheet
Dim ShtName As String, c As Range
Dim n As Long
Lr = Sheets("Person Paying").Range("B" & Rows.Count).End(xlUp).Row
For Each c In Sheets("Person Paying").Range("B1:b" & Lr)
ShtName = c.Value & " IRD"
On Error Resume Next
Set ws = Sheets(ShtName)
On Error GoTo 0
If Not ws Is Nothing Then
n = n + 1
ReDim Preserve ShtGroup(1 To n)
ShtGroup = ShtName
End If
Set ws = Nothing
Next
For Each ws In Sheets(ShtGroup)
If ws.Range("A1") <> "" Then
ws.Copy
xcsvFile = "C:\OneDrive\Houses\Business\Wages\CSV\IRD" & "\ird_" & ws.Name & ".csv"
Application.ActiveWorkbook.SaveAs Filename:=xcsvFile, _
FileFormat:=xlCSV, CreateBackup:=False
Application.ActiveWorkbook.Saved = True
Application.ActiveWorkbook.Close
End If
Next
End Sub