Results 1 to 2 of 2

Thread: Closing Userform with another Macro??
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    May 2011
    Posts
    277
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Closing Userform with another Macro??

    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?

    -OR-


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

    Code:
    Public globDate As Double, globTime As Double
    
    
    Sub Button10_Click()
    
    'get the last end time for nextjob start time
    
    Dim xLastRow As Long
              WithApplication.ActiveSheet.Range("EndTimeCol")
               xLastRow =.Cells(.Rows.Count, "a").End(xlUp).Activate
        End With
    
    Unload frmTime1
    
        globTime =ActiveCell.Value
    
    'get the last end date for the next job start date.
    
    Dim xLastRow2 As Long
              WithApplication.ActiveSheet.Range("DateCol")
                xLastRow2 =.Cells(.Rows.Count, "a").End(xlUp).Activate
          End With
    
        globDate =ActiveCell.Value
    
    Unload frmTime1
     
    'clear the last copied start time
    
    Dim xLastRow3 As Long
        
    WithApplication.ActiveSheet.Range("StartCol")
            xLastRow3 =.Cells(.Rows.Count, "a").End(xlUp).MergeArea.ClearContents
    
       End With
      Unload frmTime1
    
    
    End Sub
    Last edited by buzz71023; Jul 18th, 2019 at 04:43 PM.

  2. #2
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Closing Userform with another Macro??

    I think this should do it..


    Code:
    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

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •