+ Reply to Thread
Results 1 to 4 of 4

VBA MsgBox with vbYes and vbNo

Hybrid View

  1. #1
    Registered User
    Join Date
    05-30-2007
    Location
    Roslyn New Zealand
    MS-Off Ver
    16.0.17226.42303
    Posts
    25

    VBA MsgBox with vbYes and vbNo

    Hi

    Using this code:

    Private Sub Workbook_Open()
    
    ' Set Up  popups for action on current days(s)
    
    Dim bottomO As Integer
        Sheets("ListOfSites").Select
        bottomO = Range("O" & Rows.Count).End(xlUp).Row
            Dim c As Range
        For Each c In Range("O11:O" & bottomO)
            If c >= Date And c <= Date + 3 Then
                                                    
            MsgBox " Action TODAY :  " & c.Offset(0, -11) & c.Offset(0, -1), vbExclamation + vbYesNo
            
                       End If
        Next c
    
    'Set to open Homepage
    
    Application.ScreenUpdating = False
    
    Worksheets("Home").Activate
    
    Application.ScreenUpdating = True
    End Sub

    In an openwork book event, and selects a date with some text and y/ n options.
    Works ok. But now I want to when the 'No' is selected it opens a userform allowing user to place a number in an offset of the cell currently in focus. That is the cell that had the date in, which the code selected, is the same cell that will be entered, with an offset (say left 1col 0 -1) by the userform.


    How do I retain the focus from the Msg box into the userform, and with offset. or in the userform vba how do I get it to focus on the same cell as per the msgbox?

    Thankyou
    CharlesHarris

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,324

    Re: VBA MsgBox with vbYes and vbNo

    You need to capture and test the response:

    Option Explicit
    
    Sub sTestMsgBox()
    
    Dim vResp
    
    vResp = MsgBox("enter yes or no", vbYesNoCancel, "Test")
    If vResp = vbYes Then
        MsgBox "yes input"
    ElseIf vResp = vbNo Then
        MsgBox "no input"
    Else
        MsgBox "cancel pressed"
    End If
    
    End Sub

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    05-30-2007
    Location
    Roslyn New Zealand
    MS-Off Ver
    16.0.17226.42303
    Posts
    25

    Re: VBA MsgBox with vbYes and vbNo

    MsgBoxInputBox.xls



    HI and thanks TMS

    Have attached a sample workbook to better explain what I am tryding to do.

    In column O the user places a date via a userform, then the mssgbox selects a date with yes/no options. If yes, close mssgbox, if no, user asked on userform1 to put how many more days until message to appear.See wb and VBA. One small proble, see worksheet, best way to have the date changed in the Col O - by function or vba.

    Thankyou

    Charles

  4. #4
    Registered User
    Join Date
    05-30-2007
    Location
    Roslyn New Zealand
    MS-Off Ver
    16.0.17226.42303
    Posts
    25

    Re: VBA MsgBox with vbYes and vbNo

    Hi
    An update on my code:


    Sub test()
    Private Sub Workbook_Open()
    
    ' Set Up  popups for action on current days(s)
    
    Dim bottomO As Integer
        Sheets("ListOfSites").Select
        bottomO = Range("O" & Rows.Count).End(xlUp).Row
            Dim c As Range
        For Each c In Range("O11:O" & bottomO)
            If c >= Date And c <= Date + 3 Then
                                                    
            MsgBox " Action TODAY :  " & c.Offset(0, -11) & c.Offset(0, -1), vbExclamation + vbYesNo
            
                        End If
        Next c
    
    If MsgBox(“ Action TODAY :  ”, vbExclamation + vbYesNo) = vbNo
    
    Then Call "Userform1"
    
    If response = vbYes Then Exit Sub
    
    End If
    
    End If
    
    
    'Set to open Homepage
    
    Application.ScreenUpdating = False
    
    Worksheets("Home").Activate
    
    Application.ScreenUpdating = True
    
    End Sub
    Thanks
    Charles

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] vbNo running even if test not true
    By Daveesaunders in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2012, 03:05 PM
  2. [SOLVED] Return to InputBox based on Value AND vbYes/No
    By Nu2Java in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2012, 11:44 AM
  3. MsgBox, vbNo problem
    By Carlsbergen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-30-2010, 08:15 AM
  4. [SOLVED] MsgBox, VBYes, VBNo
    By Richard in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2006, 01:35 PM
  5. [SOLVED] default = vbNo in Msgbox
    By Alex St-Pierre in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2006, 07:30 PM

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