VBA to resize a range to fit the textbox.

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have a problem,
I need people to be able to copy and paste text from Word into excel, I have encounted a number of problems doing this as the people doing the cut and pasting are all at the lower end of the gene pool.

So after many hours of testing the only solution I could find that works perfectly is to have a textbox in excel that they can paste their word text into.
nnow this works great but I have another problem. the area height is not fixed.

I found a property in the textbox that will resize it to fit text and whilst this is not ideal it might be ok.
however I need the Sheet to respond to the change in text size.

So heres what I need

Range C110:G100 (are merged)
Textbox fits within area. (textbox is called "words 1")

when someone pastes into textbox "Words 1" resize text box height to fit all text.
Then resize
Range C110:G100 row height to be same size as textbox so textbox still fits inside.

please help if you can
Thanks
Tony
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
as the people doing the cut and pasting are all at the lower end of the gene pool
Does the above adjunct add anything to the post
confused.png




when someone pastes into textbox "Words 1" resize text box height to fit all text.
Then resize Range C110:G100 row height to be same size as textbox so textbox still fits inside

Q1 Should each of 11 row heights in Range C110:G100 be adjusted to an eleventh of textbox height ?


Q2 Have you tried right-clicking textbox and checking the box Resize shape to fit text ?
 
Last edited:
Upvote 0
Hi Yongle,

sorry mistype range should be
Range C
110
:G
110 so just one row.

Yes, right-clicking textbox and checking the box
Resize shape to fit text
? works for the text box but not the cell range so happy to use this as part of it if better.

Thanks

Tony
 
Upvote 0
One line of VBA is required to make the row height match textbox height
- the VBA could be put behind a button or triggered by a worksheet event etc
- unfortunately updating a standard textbox is not a pre-configured "event"

Code:
    ActiveSheet.Rows(110).RowHeight = ActiveSheet.Shapes("Words 1").Height

Consider using an active-X textbox which has a range of pre-configured events available for more flexibility
 
Last edited:
Upvote 0
Hi Yongle,
This is excellent thank you.
Its no problem getting the macro to trigger I have already though of that one. so that all i needed thank you.
Tony
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,454
Members
452,514
Latest member
cjkelly15

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