InputBox and vbOKCancel Help

frotaru

Board Regular
Joined
Oct 12, 2006
Messages
124
I want to use the vbOKCancel with the inputbox. Is it possible ??

Something like when InputBox prompts …. if I chose Cancel then Exit Sub
In the current code the Cancel button won’t do anything

Thank u all
Code:
If Cells.Find(What:="11 - 11", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True) Is Nothing Then
    D11ans = ""
    Else
    D11ans = " 11"
    End If
    

If D11ans <> "" Then
    D_Ans_Option = InputBox("Differences found for the following type of doc:" & D11ans)
    End If
    If D_Ans_Option = "" Then
    Do
    D_Ans_Option = InputBox(" Please make one of the following selection : " & D11ans)
    Loop While D_Ans_Option = ""
    End If
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try a msgBox. Example:

Code:
Sub Test()
    Ans = MsgBox("Differences found", vbOKCancel)
    If Ans = vbCancel Then
        Exit Sub
    Else
        MsgBox "OK pressed"
    End If
End Sub
 
Upvote 0
Good idea .. I will first start with an MsgBox..
Thank U for u’re help..

One more question is it possible to use vbOKCancel same as with MsgBox ??

Something like InputBox("Differences found for the following type of doc:" & D11ans, VbOKCancel) ????

Thank U again
 
Upvote 0
Like this?

Code:
Sub Test()
    Ans = InputBox("Differences found")
    If Ans = "" Then
        MsgBox "Cancel pressed or nothing entered      "
        Exit Sub
    Else
        MsgBox "Something entered and OK pressed"
    End If
End Sub
 
Upvote 0
in my code i use "Do" and "Loop While" .. and i think that this will remove the Cance button function ... When press nothing happens .. i tryed something like
Code:
    Do 
    D_Ans_Option = InputBox(" Please make one of the following selection : " & D11ans, VbOkCance) 
    Loop Until D_Ans_Option <> "" Or D_Ans_Option = vbCancel
    End If
but still not working ...
 
Upvote 0
InputBox doesn't have a Buttons argument like MsgBox does. It has OK and Cancel buttons by default. If the user clicks OK or presses Enter , the InputBox function returns whatever is in the text box. If the user clicks Cancel, the function returns a zero-length string (""). Of course it will also return "" if there is nothing in the text box when the user clicks OK.

What is the prupose of your Do loop?
 
Upvote 0
To validate the data value entered ... So it will loop until .. it will be one from a list.For example the list is (11, 12, 21, 41 .... ) and value entered is 11 than ok else loop .. this works fine .. but won't let me cancel the action if i want to .. But i found a solution and now all works ok. Thank u verry much for u 're time and for helping me
 
Upvote 0

Forum statistics

Threads
1,223,315
Messages
6,171,412
Members
452,399
Latest member
oranges

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top