User Form data entry as date and number!!!

NDMDRB

Board Regular
Joined
Jun 20, 2016
Messages
164
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have the code below for a user form to enter some data on my sheet "Expenses"
  • TextBox1 including date as shown on the second code
    • Once I enter the data to the sheet, it shows the date as text
  • TextBox4 including the amount
    • Once I enter the data to the sheet, it shows the number as text

I need these two boxes to insert the data as date and numbers

Is there any way to do this?

Many thanks in advanced



Code:
Private Sub CommandButton1_Click()
Dim MsgBoxResult As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Expenses")
nr = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
ws.Cells(nr, 1) = Me.TextBox1 'Date
ws.Cells(nr, 2) = Me.TextBox2 'Type
ws.Cells(nr, 3) = Me.TextBox3 'Description
ws.Cells(nr, 4) = Me.TextBox4 'Amount
MsgBoxResult = MsgBox("Your data has been added" & vbCrLf & "Do you need to add more?", vbYesNo)
If MsgBoxResult = vbNo Then
Unload Me
ElseIf MsgBoxResult = vbYes Then
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
Else
End If 
End Sub



Private Sub UserForm_Initialize()
Me.TextBox1 = Now
End Sub
 
Last edited by a moderator:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try this:

Code:
ws.Cells(nr, 1) = CDate(Me.TextBox1) 'Date
ws.Cells(nr, 2) = Me.TextBox2 'Type
ws.Cells(nr, 3) = Me.TextBox3 'Description
ws.Cells(nr, 4) = CDbl(Me.TextBox4) 'Amount
 
Upvote 0
Try this...

Code:
ws.Cells(nr, 1) = [B]CDate(Me.TextBox1)[/B] 'Date
Code:
[COLOR=#333333]ws.Cells(nr, 4) = [B]CCur(Me.TextBox4)[/B] 'Amount[/COLOR]
 
Last edited:
Upvote 0
You're welcome, glad to help, & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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