Userform throwing Error 91

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
558
Office Version
  1. 365
Platform
  1. Windows
Hi

I have a very simple user form with a command button it. The code behind the userform and button is this. Maybe I am missing something very obvious, but i don't see why this would throw an error 91.

all direction given is most appreciated

VBA Code:
Private Sub UserForm_Initialize()
    With frmTestData
            .StartUpPosition = 0
            .Left = Application.Left + (2.5 * .Width)
            .Top = Application.Top + (0.5 * Application.Height) - (0.75 * .Height)
            .Show
    End With
End Sub


Private Sub btn7columns_Click()
    With Sheet26
        .Range("A2:A250").Value = .Range("G2:G251").Value
    End With
    Unload frmTestData
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
You should invoke the Show method outside of the code module for the UserForm. So, for example, remove .Show from the initialize event, and then show your UserForm with the following code in some other module, like a regular module...

VBA Code:
frmTestData.Show

By the way, it looks like you should replace...

VBA Code:
.Range("A2:A250").Value = .Range("G2:G251").Value

with

VBA Code:
.Range("A2:A250").Value = .Range("G2:G250").Value

Hope this helps!
 
Upvote 0
Solution
Update:
When I step through the code, the error pops up when the End Sub of the Userform_Initialised is reached.
 
Upvote 0
Thanks Domenic. I read your reply after i posted the update.

The .show is what caused the problem. I have about 40 forms, many of which have the .show in the initialise.

But anyway, i have done what you suggested and problem gone.

So now I will amend all of the other forms as well and prevent any other possible situations. Thanks.
 
Upvote 0
That's great, glad I could help.

And thanks for the feedback.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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