Is there a userform deactivate command?

Botanybob

New Member
Joined
Jul 26, 2014
Messages
18
I would like the userform to be at the center of screen when activated (as normal) then move to the very bottom of screen when the worksheet behind it is clicked.

I made my worksheet modeless and made a command button to do what I want, but I want the "deselect userform" command.

This is what I have:
Code:
 Private Sub CommandButton1_Click()
   With Me
        .StartUpPosition = 0
        .Top = 630
        .Left = 0
    End With
End Sub

Thanks a bunch!
 
Learned something new here today. Never learned before of "UserForm1.Show vbModeless"
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
BotanyBob

It's really just JLGWhiz's code with a minor adjustment.:)
 
Upvote 0
This new code has presented a little bit of a problem. When users press the ok button on the userform it updates the worksheet with information from the userform (as normal), but now hides the userform. If you want the userform to appear to remain open after ok is clicked a "show userform" command must be written into userform code. This fix works, but there is a brief lag in screen updating even if "screen updating" is false.
 
Upvote 0
How are you writing the data to the worksheet?

Does it involve any selecting?
 
Upvote 0
Yes, I am selecting cells in worksheet. I will have to find another way.

Code:
Sheets("Data").Activate


Range("A4").Select
    ActiveCell.EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow
    Range("A4:T4").Borders.LineStyle = xlContinuous


Cells(4, 2) = tbTime.Text
 
Upvote 0
Well you don't actually need to Select/Activate so altering your code to get rid of that would help.

Not 100% sure how to do that right now - getting a bit late here.

In the meantime you could add this to your code to stop the SelectionChange event being triggered.
Code:
Application.EnableEvents = False

If you do add that make sure you turn events back on with this, after you've finished transferring data to the worksheet.
Code:
Application.EnableEvents = True
 
Upvote 0
I tried to insert your code before and after what I posted above and it didn't work.
I'm guessing the hide userform code in worksheet is overriding it.
I will try and find another way to insert a row than the cell selection method.
Thanks for trying it means a lot.
 
Upvote 0
The code I posted should stop the SelectionChange event being triggered, in fact it should stop all events being triggered.

Where exactly did you put the code I suggested?
 
Upvote 0
Well, actually I took another look at it and there was another select event (data sort) in the userform that was selecting the worksheet. I moved your enable events code right after the command click and before the end sub and it totally worked.
I'm going to list this thread as closed.
Thanks a ton everyone!!!
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,842
Members
449,471
Latest member
lachbee

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