Textboxes to show todays date -1 day -2 day etc

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
6,002
Office Version
  1. 2024
Platform
  1. Windows
I’m a bit lost without the Datepicker option on my userform.
So as poor as it is I’m thinking of having some option buttons or checkboxes where they could be selected, let’s say 6 of them & each one in turn would show current day, next one todays date -1 date, next one would show todays date -2 days etc etc.

Currently my existing code would look for the value in Textbox12 which would be the current day then pass that date to my worksheet.

So advice is needed for the code to take onboard the above & apply the option or checkbox which relates to a date in question then pass to the worksheet.

Basically my goal is when date picker was in use I could select a date 3 or 4 days previous to the current date & it would be put on my worksheet

So I’m trying to have the same kind of previous date selection.

Any suggestions welcome.
 
use a combobox in place of the textbox and populate in UserForm_Initialize
something like this
VBA Code:
Dim i As Long

For i = -5 To 2
    Me.ComboBox1.AddItem Date + i
Next i
 
Upvote 0
Ok so ive now applied the code & see it on the userform.

I need to now do the following.
When i open the userform i see todays date in the ComboBox BUT when i click the drop down i see the dates as mm/dd/yy as opposed to dd/mm
pLEASE ADVISE HOW & WHERE I ADD CODE TO CHANGE IT TO DD/MM/YYYY

See photo

Rich (BB code):
    Private Sub UserForm_Initialize()
        Dim i As Long
         For i = -5 To 2
            Me.ComboBox1.AddItem Date + i
           ComboBox1.Value = Format(Date, "dd/mm/yyyy")
        Next i

        TextBox2.SetFocus
        Call populate
        Application.ScreenUpdating = True
        TextBox1.Value = Format(CDbl(Date), "dd/mm/yyyy")
        OptionButton1.Value = True
        OptionButton4.Value = True
        OptionButton7.Value = True
        OptionButton13.Value = True
        PostageIssueButton.Visible = False
        
    Me.StartUpPosition = 0
    Me.Top = Application.Top + 15  ' MARGIN FROM TOP OF SCREEN
    Me.Left = Application.Left + Application.Width - Me.Width - 30 ' LEFT / RIGHT OF SCREEN HIGHER NUMBER MOVES FORM TO THE LEFT
    
    With ListBox2
        .ColumnWidths = "250;130;100"
    End With
        Label13.Visible = False
        Label14.Visible = False
        Label15.Visible = False
        Label16.Visible = False
             
        TextBox12.Value = Format(Date, "dd/mm/yyyy")
  
    End Sub

EaseUS_2025_03_ 9_10_09_35.jpg
 
Upvote 0
format the addeitem dates the way you want them
same as you did in the line you added to display the value in the combobox
 
Upvote 0
Im not to sure where or what to put.
I assume you mean in the Initiialize evert ?
If so what do i then put as tried a few options but kept getting errors thus me going round in circles so i posted here.

This now gives me a list of zeros

Basically just dont know

Rich (BB code):
    Private Sub UserForm_Initialize()
        Dim i As Long      ' THIS ADDS DATE TO COMBOBOX
         For i = -5 To 2
           Me.ComboBox1.AddItem Date + i = Format(Date, "dd/mm/yyyy")
           ComboBox1.Value = Format(Date, "dd/mm/yyyy")
        Next i
 
Upvote 0
VBA Code:
            Me.ComboBox1.AddItem Format(Date + i, "dd/mm/yyyy")
the same way you did it in the line below
 
Upvote 0
Thanks,
This is then done.

Rich (BB code):
        Dim i As Long      ' THIS ADDS DATE TO COMBOBOX
         For i = -5 To 2
           Me.ComboBox1.AddItem Format(Date + i, "dd/mm/yyyy")
           ComboBox1.Value = Format(Date, "dd/mm/yyyy")
        Next i
 
Upvote 0

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