CSV export to remove column

StellarRumble59

New Member
Joined
Apr 10, 2024
Messages
3
Office Version
  1. 365
  2. 2021
Platform
  1. 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

1712810235246.png


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
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I have realised that i need to amend again to bring up a save as folder path so the user can choose the location to save the csv's
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,217
Members
453,024
Latest member
Wingit77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top