Day of week in an excel form

mecerrato

Board Regular
Joined
Oct 5, 2015
Messages
174
Office Version
  1. 365
Platform
  1. Windows
I have an excel form that I enter a date and after tabbing to the next field I would like a label to show the day of the week. I am able to create a label to the right of the date field but cannot figure out where or how to put the LabelClosingDay = Weekday(TextBoxClosingDate) so that it calculates the day after tabbing from the date field.
1690207819626.png
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Assuming the Textbox you're entering the date in is
TextBox1 and the label is Label2 try this.
Modify Textbox and label names to meet your needs.

VBA Code:
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo M
Label2.Caption = Weekday(TextBox2.Value)
Exit Sub
M:
MsgBox "You entered " & TextBox2.Value & vbNewLine & "That is not a proper Date"
End Sub
 
Upvote 0
Assuming the Textbox you're entering the date in is
TextBox1 and the label is Label2 try this.
Modify Textbox and label names to meet your needs.

VBA Code:
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo M
Label2.Caption = Weekday(TextBox2.Value)
Exit Sub
M:
MsgBox "You entered " & TextBox2.Value & vbNewLine & "That is not a proper Date"
End Sub
This kinda works, but it is giving me a number rather than a day like Monday or Tuesday
Here is the code with the correct txtbox and label names
VBA Code:
Private Sub TextBoxClosingDate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo M
LabelClosingDay.Caption = Weekday(TextBoxClosingDate.Value)
Exit Sub
M:
MsgBox "You entered " & TextBoxClosingDate.Value & vbNewLine & "That is not a proper Date"
End Sub
 
Upvote 0
Glad to see you have it working for you.
Yes, I was not sure if you want 3 or Tuesday.

It's always good to see how users can see how the scripts work and can modify them to their needs.

I also added the part about On Error
That is so if someone enters something that is not a proper date you will get a popup message and not have the script lockup.
 
Upvote 0
Glad to see you have it working for you.
Yes, I was not sure if you want 3 or Tuesday.

It's always good to see how users can see how the scripts work and can modify them to their needs.

I also added the part about On Error
That is so if someone enters something that is not a proper date you will get a popup message and not have the script lockup.
Thanks but can you tell me how I can make it show the day and not the number?
 
Upvote 0
Try this modify names of controls:

I now have dddd Which means like Wednesday.
If you want like Wed
change to dd if you want Wed
VBA Code:
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo M
Label2.Caption = Format(TextBox2.Value, "dddd")

Exit Sub
M:
MsgBox "You entered " & TextBox2.Value & vbNewLine & "That is not a proper Date"
End Sub
 
Upvote 0
Solution
Try this modify names of controls:

I now have dddd Which means like Wednesday.
If you want like Wed
change to dd if you want Wed
VBA Code:
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo M
Label2.Caption = Format(TextBox2.Value, "dddd")

Exit Sub
M:
MsgBox "You entered " & TextBox2.Value & vbNewLine & "That is not a proper Date"
End Sub
Thank you very much!
on a side note, do you have a resource for adding an easy date picker to this form. It seems like allt he date pickers I have googled require a lot of coding
 
Upvote 0
Thank you very much!
on a side note, do you have a resource for adding an easy date picker to this form. It seems like allt he date pickers I have googled require a lot of coding
From what I've learned your version of Excel is a part of Office 365. And that version of Excel does not support Date Picker
My version also does not support Date Picker
 
Upvote 0

Forum statistics

Threads
1,215,190
Messages
6,123,547
Members
449,107
Latest member
caya

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