Macro to add Columns to existing CSV file

JWelch69

New Member
Joined
May 18, 2011
Messages
1
I am new to the group and it looks like there are a LOT of knowledgeable folks out there.
I'm hoping I can get some help.
I am looking to create a macro for Excel that will allow the user to select an existing CSV file, then will add 2 columns to the END of the existing columns and create a header at the top, but populate the columns with text (the same text for each column). But it should ONLY populate that column with this test ONLY to the end of the longest column that already exists. (So if the file has 450 records, it should only add the column and the text up to 450 rows)
I have started trying things, but feel that I may be out of my league.
It needs to keep the resulting file as a CSV.
Here is what I have so far, but it is not close....this will add a column, but only if the file has been opened and a cell selected. And it will add the MAX # of rows (65536 in my test).
Any help is appreciated.


Sub Add_Column()

Dim Range1 As Object

Set Range1 = Selection

Selection.EntireColumn.Select

Selection.Insert

Selection.FormulaR1C1 = "Test1"

Range1.Select
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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