Autofit Row Height

Chewyhairball

Board Regular
Joined
Nov 30, 2017
Messages
108
Hi
I have a range of cells Sheet1 C7:C1000 that autofit the row height when the data in those cells is changed.
The data is pulled from another sheet and updates when I type certain criteria into a combobox.

It works great and when more text is pulled through it automatically changes the the row height as I am typing in the combobox.

The VBA i have is a Worksheet_Calculate but i have found that it also tries to run if i am on other sheets and change C7:C1000 on them.

I thought putting the event in the specific sheet would mean it only ran on that sheet but its not the case.

I tried a Worksheet Change but that doesnt give me what i need as it required a <return> and thats not how my sheet runs. I use the combobox and it changes the data in the rows as i type.

Any ideas how I can keep my code but only have it run on the one sheet. Thanks

VBA Code:
Private Sub Worksheet_Calculate()
 Dim Xrg As Range
    Set Xrg = Range("C7:C1000")
    If Not Intersect(Xrg, Range("C7:C1000")) Is Nothing Then
    rowheight
    End If
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,806
Office Version
  1. 365
Platform
  1. Windows
That will only run if that sheet is calculated, but it will run whenever any formulae on the sheet recalculate.
 

Chewyhairball

Board Regular
Joined
Nov 30, 2017
Messages
108
That will only run if that sheet is calculated, but it will run whenever any formulae on the sheet recalculate.
Yes. If I make a change to cells in sheet 2 it tries to run the code and errors. It’s a pain. 🙄
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,806
Office Version
  1. 365
Platform
  1. Windows
If the rowheight code is crashing, I'd suggest starting a new thread asking how to prevent that.
 

Chewyhairball

Board Regular
Joined
Nov 30, 2017
Messages
108
If the rowheight code is crashing, I'd suggest starting a new thread asking how to prevent that.
Thanks. It works perfect as long as there are no other sheets being used. Think I’ll just have it as a separate worksheet. I’ve got to many tabs as it is. 🙂 cheers.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,072
Messages
5,639,896
Members
417,116
Latest member
Ravi Pandey

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
Top