Create User Input message box with 2 options; enter specific date or check checkbox

Tardisgx

Board Regular
Joined
May 10, 2018
Messages
81
Below I have VBA for a user to enter a date and for that to be entered into a specific cell on the active sheet. I do not have a lot of experience with Or statements.

I want to add an "or" path for a checkbox to be ticked, if this is the case then yesterday's date; formula =today()-1 would be entered in the cell instead. Disallow both a value to be entered and the check box to be ticked.

Code:
Sub Which Date

    Dim QtyEntry As Integer
    Dim Msg As String
    Msg = "Enter Specific Date dd/mm/yy"
    QtyEntry = InputBox (Msg)
    ActiveSheet.Range("B2").Value = QtyEntry

End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
How about this?

Code:
Sub Which Date
Dim QtyEntry As Date
Dim Msg As String
Msg = "Enter Specific Date dd/mm/yy"


If ActiveWorkbook.Sheets("Sheet1").CheckBox1.Value = True Then
    ActiveSheet.Range("B2").Value = Date - 1
Else
    QtyEntry = InputBox(Msg)
    ActiveSheet.Range("B2").Value = QtyEntry
End If
End Sub
 
Upvote 0
Thanks for your input; I have been able to write my own code; I have made some progress but this simple thing is not working.

https://imgur.com/GgQNEWB

My issue is the textbox value is not being read when I click proceed. No Date appears in B2



When I check the box and click proceed; that works fine. date in B2 Appears.



Specifictext refers to the blank textbox.

YesterdaysDate refers to the checkbox

Code:
Private Sub Proceed_Click()
Dim Specifictext As String
If YesterdaysDate Then
ActiveSheet.Range("B2").FormulaR1C1 = "=TODAY()-1"
ElseIf Specifictext <> "" Then
ActiveSheet.Range("B2").Value = Specifictext
End If
End Sub
 
Last edited:
Upvote 0
I have received a new solution from another reply. Thanks for your input

Code:
Private Sub Proceed_Click()
    If YesterdaysDate Then
        'check to make sure both fields aren't being used
        If Not Me.Specifictext.Value = vbNullString Then
            MsgBox "both cannot be used"
            Me.Specifictext.SetFocus
            Exit Sub
        Else
            ActiveSheet.Range("B2").FormulaR1C1 = "=TODAY()-1"
        End If
    ElseIf Not Me.Specifictext.Value = vbNullString Then
        ActiveSheet.Range("B2").Value = Me.Specifictext.Value
    Else 'assuming both cannot be left blank
        MsgBox "both cannot be blank"
        Me.Specifictext.SetFocus
        Exit Sub
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,427
Messages
6,124,830
Members
449,190
Latest member
rscraig11

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