Cell sizing

JackReacher85

Banned user
Joined
Sep 14, 2021
Messages
12
Office Version
  1. 2016
Platform
  1. Windows
Hi guys,

Ive got the below formula

=VLOOKUP(C20:C22,Sheet2!A1:B21,2,0)

Which returns the results i need and it works as it should, however when the formula returns the values the cell doesnt show the entire result, and what im looking to do is have the cell automatically adjust so it fits all of the result so it can be read by the user. I know that Excel has the auto fit option in the format tab but this requires the user to manually do this every time the formula is run.

Any ideas on how i can have the cell expand and contract accordingly to the result that is populated in the cell?

Thanks in advance
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Which cell is the formula in?
 
Last edited:
Upvote 0
Paste this code into the Worksheet that the formula is in.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("A1") Then       <----------Change the value to match the cell that your formula is in.
    Columns(1).AutoFit                   <----------Change the value to match the column number that your formula is in.
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,174
Messages
6,123,454
Members
449,100
Latest member
sktz

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