set column width

virgil

New Member
Joined
Mar 1, 2011
Messages
3
I am completely new to some of this and am lost as to how to set column widths in excel using a macro. My problem is I don't have any experience with this process. What I need is a macro that lets me set different widths for seven columns on a csv worksheet I have. Any and all help will be greatly appreciated.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hello,
Welcome to the Message Board!!

Here is a sample from the macro recorder:

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Macro1()<br><SPAN style="color:#007F00">'</SPAN><br><SPAN style="color:#007F00">' Macro1 Macro</SPAN><br><SPAN style="color:#007F00">'</SPAN><br><br><SPAN style="color:#007F00">'</SPAN><br>    Columns("A:A").ColumnWidth = 34.71<br>    Columns("B:B").ColumnWidth = 16.57<br>    Columns("C:C").ColumnWidth = 23.71<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
And here's another:-
Code:
Sub Macro1()
[COLOR=green]'
' Macro1 Macro
'[/COLOR]
[COLOR=green]'
[/COLOR]    Columns("E:E").EntireColumn.AutoFit
End Sub
You know that column widths aren't saved with a CSV file, yes? Next time you open it, the column widths will all be set to default.
 
Upvote 0
Many thanks for the reply, but I still can't get it to work. I may not be saving the macro properly or something. I will continue to resize while working on the spreadsheet. Maybe one of these days I will figure it out. :(
 
Upvote 0
Hi,
Sorry about the delay in responding to your post but have been out of pocket a few days. I was saving it as a macro in the workbook but it would not save for some reason. I finally went to the record macro feature and finally got it to save in the personal.xlsb file. Now I just use the hot key I set up and the columns auto resize.

Again, many thanks and I will probably be needing assistance in the future.

Virgil:)
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,854
Members
452,948
Latest member
UsmanAli786

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