Closing Userform with another Macro??


Active Member
May 29, 2011
I need some help here. Hopefully it won’t be too confusing.

I have the below code that code is supposed to be lookingthrough the range, setting a couple of variable, and then deleting the last usedcell in a range but the problem is it keeps bringing up a userform (frmTime1)while the code is running and I do not want it to.

The problem is within this range, when any of the cells areselected by the user (using Worksheet_SelectionChange), I have a userform that is supposed to pop up to allow theuser to enter their data.

Is there a way to declare these variable which would be thelast data in range(s) DateCol and EndCol and then would also find the last data inrange StartCol and clear contents WITHOUT bringing up the userform?


Is there a way to close the userform that pops up after ispops up with in the code?

[FONT=Calibri][SIZE=3][COLOR=#000000]Public globDate As Double, globTime As Double[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]Sub Button10_Click()[/COLOR][/SIZE][/FONT]
'get the last end time for nextjob start time[/COLOR][/SIZE][/FONT]
Dim xLastRow As Long[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]          WithApplication.ActiveSheet.Range("EndTimeCol")[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]           xLastRow =.Cells(.Rows.Count, "a").End(xlUp).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]    End With[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]Unload frmTime1[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]    globTime =ActiveCell.Value[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]'get the last end date for the next job start date.[/COLOR][/SIZE][/FONT]
Dim xLastRow2 As Long[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]          WithApplication.ActiveSheet.Range("DateCol")[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]            xLastRow2 =.Cells(.Rows.Count, "a").End(xlUp).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]      End With[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]    globDate =ActiveCell.Value[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]Unload frmTime1[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]'clear the last copied start time[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]Dim xLastRow3 As Long[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]        xLastRow3 =.Cells(.Rows.Count, "a").End(xlUp).MergeArea.ClearContents[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]   End With[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] [FONT=Calibri][SIZE=3][COLOR=#000000] Unload frmTime1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]
Last edited:

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.


Board Regular
Apr 28, 2010
I think this should do it..

Public doRun As Boolean
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If doRun Then
        'Your existing SelectionChange code goes here...
    End If
End Sub

Sub Button10_Click()
    doRun = False
    'get the last end time for nextjob start time
    ' Your existing code Goes here

    doRun = True 'This needs to happen at the end of your button click event
End Sub

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...