+ Reply to Thread
Results 1 to 7 of 7

Msg box response is ignored

Hybrid View

  1. #1
    Registered User
    Join Date
    04-26-2009
    Location
    Norfolk
    MS-Off Ver
    Excel 2003
    Posts
    9

    Msg box response is ignored

    Hello,

    I am trying to achieve a response from a msgbox which will either continue with the sub or exit. I think my code is right but it doesn't seem to work and just carrys on regardless. Any help would be appreciated.

    Private Sub CommandButton1_Click()
    
    Dim MSG1 As Integer
    
    MSG1 = MsgBox("Send Scaffold to destruct?", vbCritical)
    
    If MSG1 = vbCancel Then
    
    Exit Sub
    
    Else
     
    Worksheets("sheet2").Activate
    
    ActiveSheet.Range("b4").Select
    
    Do
    
    If IsEmpty(ActiveCell) = False Then
    
        ActiveCell.Offset(1, 0).Select
       
    End If
    
    Loop Until IsEmpty(ActiveCell) = True
        
        
        
        Worksheets("sheet1").Range("A4:h4").Copy
        
        Worksheets("sheet2").Paste Destination:=ActiveCell.Offset(0, -1)
              
        Worksheets("sheet1").Activate
        
        Worksheets("Sheet1").Rows(4).Delete
    
    End If
       
    End Sub
    Last edited by aaron.ronnie; 04-29-2009 at 05:37 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Msg box response is ignored

    Welcome to the forum. One of the important forum rules is to wrap [code] [ /code] tags around your posted code. Please go back to your original post, click on GO ADVANCED, then highlight the code and click on the # icon...thanks, it makes the forum SO much easier to read, and it's a rule! Notice how much easier it is to read my code below.

    Meanwhile...try this:
    Private Sub CommandButton1_Click()
    
    If MsgBox("Send Scaffold to destruct?", vbYesNo + vbCritical) = vbNo Then Exit Sub
    
    Worksheets("sheet2").Activate
    ActiveSheet.Range("b4").Select
    
        Do
            If IsEmpty(ActiveCell) = False Then ActiveCell.Offset(1, 0).Select
        Loop Until IsEmpty(ActiveCell) = True
    
    Worksheets("sheet1").Range("A4:H4").Copy
    Worksheets("sheet2").Paste Destination:=ActiveCell.Offset(0, -1)
    
    Worksheets("sheet1").Activate
    Worksheets("Sheet1").Rows(4).Delete
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    04-21-2007
    Location
    Lima, Peru
    MS-Off Ver
    2000, 2007, 2010
    Posts
    674

    Re: Msg box response is ignored

    Hi

    Try the following code, which splits up your macro in to two parts one for the button and one for the code you wish to call.

    Private Sub CommandButton1_Click()
    
    Dim Msg, Style, Title, Response
    Msg = "Send Scaffold to destruct?"
    Style = vbYesNo + vbCritical
    Title = "Scaffold Destruct"
    
    Response = MsgBox(Msg, Style, Title)
    If Response = vbYes Then
    Call scaffold
    Else
    End
    End If
    
    End Sub
    
    Sub scaffold()
    
    Worksheets("sheet2").Activate
    
    ActiveSheet.Range("b4").Select
    
    Do
    
    If IsEmpty(ActiveCell) = False Then
    
    ActiveCell.Offset(1, 0).Select
    
    End If
    
    Loop Until IsEmpty(ActiveCell) = True
    
    
    Worksheets("sheet1").Range("A4:h4").Copy
    
    Worksheets("sheet2").Paste Destination:=ActiveCell.Offset(0, -1)
    
    Worksheets("sheet1").Activate
    
    Worksheets("Sheet1").Rows(4).Delete
    
    
    End Sub
    Regards

    Jeff

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Msg box response is ignored

    I have added Code Tags this time, please be sure to read the Forum rules before posting again.

    This code asks for a response then copies the data. Note it does not use the loop - which would take longer, nor is it necessary to activate or select sheets and ranges

    Option Explicit
    
    Private Sub CommandButton1_Click()
        Dim NextCl As Range
    
        Select Case MsgBox("Send Scaffold to destruct?", vbYesNo Or _
                                                         vbQuestion Or vbDefaultButton1, "Action")
            Case vbYes
                With Worksheets("sheet2")
                    Set NextCl = .Cells(.Rows.Count, 2).End(xlUp).Offset(1, 0)
                    Worksheets("sheet1").Range("A4:h4").Copy NextCl
                    Worksheets("Sheet1").Rows(4).Delete
                End With
            Case vbNo
                Exit Sub
        End Select
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Msg box response is ignored

    aaron.ronnie

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  6. #6
    Registered User
    Join Date
    04-26-2009
    Location
    Norfolk
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Msg box response is ignored

    That's fantastic! They all work, there is plenty of learning for me there! Thank you all for your rapid response. Apologies for the mistake with my thread. Still not quite sure how to 'add tags' but I will make sure I learn and do it right next time.

  7. #7
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: Msg box response is ignored

    You habe indicated that the replies have resolved your pronlem - Please mark your thread as Solved

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    Re Wrapping VBA code

    The easiest way to use code tags is to click on the # icon in the text formatting window

    This will add
    [ Code] [\ Code]
    to your message window with the cursor between the ][ brackets - this is were your VBA code goes.
    You will not see your code displayed correctly until you preview or post your message

    Note:- there is no space before the word Code like I have shown in the example above

    On posted correctly
    your VBA code will
    appear in its own 
    scrollable window
    within your message
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1