thedeadzeds
Active Member
- Joined
- Aug 16, 2011
- Messages
- 451
- Office Version
- 365
- Platform
- Windows
Guys, is there a way to filter by each name in column D and then save these as a separate CSV file and name it based on the name in column D.
Something similar to the below code which works fine but this saves based on the worksheet name. Ideally i dont want to create a new worksheet for each name in column D i just want to filter by column D and save as CSV
Something similar to the below code which works fine but this saves based on the worksheet name. Ideally i dont want to create a new worksheet for each name in column D i just want to filter by column D and save as CSV
Code:
Sub Copy()
Dim ws As Worksheet, newWb As Workbook
Set MyRange = Sheets("Date").Range("A1") 'with the name of a cell
For Each ws In Sheets(Array("Bristol", "Bath", "Cardiff", "Newport"))
ws.Copy
Set newWb = ActiveWorkbook
With newWb
.SaveAs Filename:="C:\User\OneDrive\TEST\" & ws.Name & " " & MyRange.Value & " " _
& " " & Range("R" & Rows.Count).End(xlUp).Row - 1 & " " & ".csv", FileFormat:=xlCSV
.Close (False)
End With
Next ws
End Sub