Need help in modification of my current code. Thanks for helping!

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi,
My current code below.

I need help in modifying this code.
If user clicks on cancel exit sub - msgbox "canceled".
if inputbox.value = "" then exit sub msgbox "canceled - no date".
if date is not entered and random number is entered then msgbox "incorrect date entered..."
else run my code.
Any assistance will be appriciated.
Thanks alot in advance!


Code:
Private Sub CommandButton1_Click()
x = InputBox("Enter Date", "Date input", Format(Date, "mm/dd/yyyy"))
Range("M39").Value = x
 If Range("N39").Value = "Yes" Then
  MsgBox "U have done this" & Range("M39").Value & "Please enter another date"
    Exit Sub
     Else
    updddate
   updatetime
 End If
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi Pedie

Try.

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()<br>x = InputBox("Enter Date", "Date input", Format(Date, "mm/dd/yyyy"))<br><SPAN style="color:#00007F">If</SPAN> x = "" <SPAN style="color:#00007F">Then</SPAN><br>  MsgBox "canceled / No date"<br>  <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> IsDate(x) <SPAN style="color:#00007F">Then</SPAN><br>  MsgBox "incorrect date entered..."""<br>  <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>Range("M39").Value = x<br> <SPAN style="color:#00007F">If</SPAN> Range("N39").Value = "Yes" <SPAN style="color:#00007F">Then</SPAN><br>  MsgBox "U have done this" & Range("M39").Value & "Please enter another date"<br>    <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>     <SPAN style="color:#00007F">Else</SPAN><br>    <SPAN style="color:#007F00">'updddate</SPAN><br>   <SPAN style="color:#007F00">'updatetime</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Was thinking something along the lines of this:

Code:
Sub Test_()

On Error GoTo ErrHandler:
x = InputBox("Enter Date", "Date input", Format(Date, "mm/dd/yyyy"))

Select Case x

Case vbCancel
    MsgBox "CANCELLED"
        Exit Sub
Case vbNullString
    MsgBox "CANCELLED - NO DATA!"
        Exit Sub
End Select

If IsDate(x) = True Then

    Range("M39").Value = x
        If Range("N39").Value = "Yes" Then
            MsgBox "U have done this" & Range("M39").Value & "Please enter another date"
            Exit Sub
        Else
            'updddate
            'updatetime
        End If
Else
    MsgBox "You did not enter a valid date"
    Exit Sub
End If

Exit Sub
ErrHandler:
        MsgBox Err.Number & " " & Err.Description
        
End Sub
 
Upvote 0
Hi Brian, and hi SeenFresh:)

Great, worked perfect. Thanks for always coming to my rescue.

You have a Great day ahead!


Pedie;)
 
Upvote 0

Forum statistics

Threads
1,214,567
Messages
6,120,268
Members
448,953
Latest member
Dutchie_1

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