Consulting

Results 1 to 7 of 7

Thread: Using Yes No Message Box

  1. #1

    Using Yes No Message Box

    Hi,

    I don't understand how to use "Yes No Message Box".

    What I need is:

    After I run the Marco, a message box with a yes button and a no button will appear.

    If I click Yes, the text in cell C3 will be deleted.
    If I click No, the text in cell C3 will be not deleted.


    Could you please write the marco for me?


    What I need seem unnesscary to use marco, but the actual marco I am writing is not the one in this thread.

    Thanks

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    try

    [vba]
    Sub del()
    response = MsgBox("question?", vbYesNo + vbQuestion, "title")
    If response = vbYes Then
    Range("C3").ClearContents
    End If
    End Sub
    [/vba]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    or


    [vba]
    Sub dellll()
    If MsgBox("question?", vbYesNo + vbQuestion, "title") = vbYes Then
    Range("C3").ClearContents
    End If
    End Sub
    [/vba]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    or

    [VBA]Sub clearcell()
    If CBool(vbNo - MsgBox("delete c3?", vbYesNo)) Then
    Range("C3").ClearContents
    End If
    End Sub[/VBA]
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  5. #5
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location

    One More Way!

    [VBA]Sub DeleteCellContent()

    Dim Decision As VbMsgBoxResult

    Decision = MsgBox("Do yo want to delete content in Cell C3?", vbYesNo, "DECIDE")
    Select Case Decision
    Case 6 'Yes case
    Range("C3").ClearContents
    Case 7 'No case
    'Do nothing
    End Select

    End Sub
    [/VBA]
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  6. #6
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    You could even turn mine into a one-liner (Rick Rothstein would be proud):


    [vba]Sub clearcell()
    If CBool(vbNo - MsgBox("delete c3?", vbYesNo)) Then Range("C3").ClearContents
    End Sub[/vba]
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  7. #7
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [VBA]If MsgBox("delete c3?", vbYesNo) = vbYes Then Range("C3").ClearContents[/VBA]

Posting Permissions

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