Userform.Show gives runtime error on form close with new code?

mwisnefsky

New Member
Joined
Sep 3, 2013
Messages
14
Hello,

I just started using Userforms to help force data entry to be correct. I was having difficulty getting the form to appear in the middle of the excel window though, so I looked online and found the following code snipped to add to the initialize sub:

Code:
    With barcode        .StartUpPosition = 0
        .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
        .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
        .Show
        End With

So I added that code, clicked the button that runs the
Code:
Userform.Show
command, the form popped up in the middle of the excel window and everything was great. However, I go and close that window, and I get "Run-time error '91': Object variable or With block variable not set" and its highlighting the
Code:
Userform.Show
command as the problem line.

Before I added the code to control the starting position it worked fine. Any ideas why it would error out there? Any particular code in this you need to see?
 
Thanks for the feedback and well done on searching for a solution first.

Welcome to the forum.
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
AlphaFrog,

I've been trying to solve this problem for hours and it was driving me CRAZY!!! :eek: I was on the edge of the bridge when I tried your suggestion...IT WORKED GREAT!!!! I REALLY, REALLY appreciate your time!

Jeff
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,231
Members
449,091
Latest member
jeremy_bp001

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