Help needed to catch a bug

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I am challenged with this code and I need help to fix it.
I want to dynamically grow the height of my userform based on the visibility status of some controls as seen from my script below.

The only issue is that I have spent hours trying to figure out the right way to do it but none has given me something cooler.

The controls: exp3, exp5, exp7 and so on are those switching the visibility of exp4, exp6, exp8 and so on.

So I am calling this macro inside the change event of exp3, exp5, exp7 and so on. When exp3, exp5, exp7 and so on contain data, I make visible, exp4, exp6, exp8 and so on else I hide them.

I was thinking that I should be able to control the height of my form as well but it turned out my knowledge level is a bit limited in doing such trick at the moment.

I need someone to pull me out. Thanks in advance.

Code:
Sub checkActiveBox()
    Dim n&, s#, TbRay, j&
    TbRay = Array( _
                164.25, 189.75, 213.75, 237.75, 261, _
                285.75, 309, 333, 357.75, 380.25, 404.25, 429, 453.75, 477 _
                 )
    'j = 0
    For i = 4 To 30 Step 2
        If Controls("exp" & i).Visible = True Then
            j = i - 4
        Else
            j = 0
        End If
    Next i
    Me.Height = TbRay(j)
End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,216,075
Messages
6,128,665
Members
449,462
Latest member
Chislobog

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