Macro to change cell sizes - widths & heights

IainD

Board Regular
Joined
Jun 25, 2007
Messages
75
Each day our accounts department export a report into Excel.

The width of the report means that if it was printed, the far right of the report would print on an additional page.

I am trying to create a macro that will format the cell widths & heights, wrapping the text, so that the width of the report will print on a single page.

My questions are:

1) Is it possible to create a macro to change the cell widths & heights to specific sizes, wrapping the text?

2) If it is possible, can someone let me have some example code to change two different cells widths & heights, with the text forced to wrap?

Any help or advice would be very much appreciated.

Kind regards,

Iain.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try like this

Code:
Sub wid()
With Range("A1").EntireColumn
    .ColumnWidth = 10
    .WrapText = True
End With
With Range("C1").EntireColumn
    .ColumnWidth = 12
    .WrapText = True
End With
End Sub
 
Upvote 0
Thanks for the reply, that's a massive help.

One follow up question.

Is it possible to change the page setup to landscape using a macro?

Kind regards,

Iain.
 
Upvote 0
Thanks that's brilliant.

Is there a resource that has all these types of commands listed?

Very good of you to take the time to help, much appriciated.

Kind regards,

Iain.
 
Upvote 0
You can get the syntax for most things by recording a macro whilst performing the action manually.
 
Upvote 0
Thanks for all your help. I do appricate you taking time out to share your knowlage with a stranger.

Cheers,

Iain.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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