Autofit Cells

SDave

Board Regular
Joined
Aug 12, 2008
Messages
152
Office Version
  1. 365
Platform
  1. MacOS
I currently have a matrix - 5 rows down and 3 columns across.

The matrix pulls data from another worksheet in my workbook through the use of a macro.

Is there an autofit code I can use so that the data pulled is readable, it's rather squished at the moment.

The range that I am working with is C12:L16
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You could use something like this:

Code:
Private Sub Worksheet_Calculate()
Columns("C:L").AutoFit
End Sub

Right click on the worksheet tab and select View Code and paste onto resulting code page.

Dom
 
Upvote 0
Thanks guys - much appreciated.

I've given both code's a go and both seem to shrink the size of columns J:L without expanding C:I.

The cells aren't merged so I can't think why the columns aren't expanding to autofit?!

The way in which the worksheet works is that each cell in the matrix references a cell on another worksheet. Once the macro is run the data is pulled and inserted into it's appropriate section...

I think the reason why the columns aren't auto fitting may have something to do with the fact that the matrix is pulling data from another worksheet however I can't be certain.
 
Upvote 0
Not sure, works fine for me if I create a matrix in C12:L16 using formula like =Sheet2!C1

Dom
 
Upvote 0
Maybe try:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Range("C12:L16"), Target) Is Nothing Then Exit Sub
Columns("C:L").AutoFit
End Sub

Dom
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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