StellarRumble59
New Member
- Joined
- Apr 10, 2024
- Messages
- 3
- Office Version
- 365
- 2021
- Platform
- Windows
I could use some assistance with the below coding
When i run the process to export in CSV is there a way i can get it paste without the category column and still save based on the category?
I really did try to get this on my own....lol
Dim ws As Worksheet
Dim lastRow As Long
Dim uniqueValues As Collection
Dim value As Variant
Dim csvPath As String
Dim csvFileName As String
Dim rng As Range
Dim cell As Range
' Set the target worksheet (change "Sheet1" to your desired sheet name)
Set ws = ThisWorkbook.Worksheets("IMPORT_REPORT")
' Unprotect Sheet
Worksheets("IMPORT_REPORT").Unprotect
' Delete rows 1 to 4
Worksheets("IMPORT_REPORT").Rows("1:4").EntireRow.Delete
' Find the last row in Column A
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
' Create a collection to store unique values from Column A
Set uniqueValues = New Collection
' Loop through Column A and collect unique values
On Error Resume Next
For Each cell In ws.Range("A2:A" & lastRow)
uniqueValues.Add cell.value, CStr(cell.value)
Next cell
On Error GoTo 0
' Export separate CSV files for each unique value
For Each value In uniqueValues
' Create a new workbook to store the filtered data
Set rng = ws.Range("A1").CurrentRegion
rng.AutoFilter Field:=1, Criteria1:=value
Set rng = rng.SpecialCells(xlCellTypeVisible)
' Define the CSV file path and name
csvPath = "C:\Users\me\Downloads\EXPORT\"
csvFileName = value & ".csv"
' Save the visible range as a CSV file
rng.Copy
With Workbooks.Add(1)
.Sheets(1).Paste
.SaveAs Filename:=csvPath & csvFileName, FileFormat:=xlCSV, CreateBackup:=False
.Close SaveChanges:=False
End With
' Clear the filter
ws.AutoFilterMode = False
Next value
When i run the process to export in CSV is there a way i can get it paste without the category column and still save based on the category?
I really did try to get this on my own....lol
Dim ws As Worksheet
Dim lastRow As Long
Dim uniqueValues As Collection
Dim value As Variant
Dim csvPath As String
Dim csvFileName As String
Dim rng As Range
Dim cell As Range
' Set the target worksheet (change "Sheet1" to your desired sheet name)
Set ws = ThisWorkbook.Worksheets("IMPORT_REPORT")
' Unprotect Sheet
Worksheets("IMPORT_REPORT").Unprotect
' Delete rows 1 to 4
Worksheets("IMPORT_REPORT").Rows("1:4").EntireRow.Delete
' Find the last row in Column A
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
' Create a collection to store unique values from Column A
Set uniqueValues = New Collection
' Loop through Column A and collect unique values
On Error Resume Next
For Each cell In ws.Range("A2:A" & lastRow)
uniqueValues.Add cell.value, CStr(cell.value)
Next cell
On Error GoTo 0
' Export separate CSV files for each unique value
For Each value In uniqueValues
' Create a new workbook to store the filtered data
Set rng = ws.Range("A1").CurrentRegion
rng.AutoFilter Field:=1, Criteria1:=value
Set rng = rng.SpecialCells(xlCellTypeVisible)
' Define the CSV file path and name
csvPath = "C:\Users\me\Downloads\EXPORT\"
csvFileName = value & ".csv"
' Save the visible range as a CSV file
rng.Copy
With Workbooks.Add(1)
.Sheets(1).Paste
.SaveAs Filename:=csvPath & csvFileName, FileFormat:=xlCSV, CreateBackup:=False
.Close SaveChanges:=False
End With
' Clear the filter
ws.AutoFilterMode = False
Next value