Need to write a macro to delete columns in a CSV file

araghupa

New Member
Joined
Dec 26, 2006
Messages
16
Hi,

I have a CSV file with the following columns:

column1, Column2, Column3
A, B, "C,D"

I need to write a macro to :
1. Delete column2
2. Save the CSV file. At the time of saving I need to supress all default messages.

Thanks,
AR
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Code:
Application.DisplayAlerts = False
Thisworkbook.SaveAs "c:\test\test.csv", xlCSV
Application.DisplayAlerts = True
 
Upvote 0
Hi Jindon,

I need to specify the column name to delete a column instead of specifying a range. Will that be possible?

Thanks
 
Upvote 0
I tried it Jindon.

My column names are:
Number, Description, Filter, Automate

I need to delete columns filter and automate. I cannot specify the same in the range. This column Filter can be any column in the CSV file.
 
Upvote 0
I tried it Jindon.

My column names are:
Number, Description, Filter, Automate

I need to delete columns filter and automate. I cannot specify the same in the range. This column Filter can be any column in the CSV file.
try something like this
Code:
Dim e
With Sheets(1)
    On Error Resume Next
    For Each e In Array("Number","Description","Filter","Automate")
        .Cells.Find(e,,,xlWhole).EntireColumn.Delete
    Next
End With
 
Upvote 0
One more question Jindon.

Can I run a macro on a CSV file by storing the code of macro in notepad.
 
Upvote 0
just change csv to .txt and xlText
Code:
Application.DisplayAlerts = False
Thisworkbook.SaveAs "c:\test\test.txt", xlTEXT
Application.DisplayAlerts = True
 
Upvote 0
I think I confused you by not wording my question correctly.

I need to open the CSV (which i will do manually) and then I need to run the macro automatically as soon as the CSV is open. This has to happen everytime the CSV is opened.
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,352
Members
449,080
Latest member
Armadillos

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