VB error relating to Textbox format

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,604
Office Version
  1. 365
Platform
  1. Windows
Hi all

when my userform is activated this code kicks in

Code:
Private Sub UserForm_Activate()

        With Worksheets("database")
        TextBox2 = Format(.Cells(.Rows.Count, "b").End(xlUp).Value, "ddmmmyy")
        
    End With
End Sub

when the user inputs all the data into the userform and then selects the add button, all the Textboxes, ComboBoxes etc are copied to a sheet. However the code sticks with an error 'type mismatch on this code

Code:
With ws.Cells(iRow, 2)
    .NumberFormat = "ddmmmyy"
    .Value = CDate(Me.TextBox2.Value)
     TextBox2 = Format(.Cells(.Rows.Count, "b").End(xlUp).Value, "ddmmmyy")

with
Code:
.Value = CDate(Me.TextBox2.Value)
being the highlighted error part

can this be fixed to stop the error?
Many thanks in advance
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi,

What are you entering into the textbox? CDate expects a date (something like 01/01/2011).
 
Upvote 0
Hi James
The textbox is auto populated by the last found value in column B of the database sheet.
This column is formatted as a Custom value formatted ddMmmyyyy
So if I click on the last value in column B at the moment it shows the value in the view bar as 04/05/2011 however the actual value in the cell is 04May2011

thanks
 
Upvote 0
Off the top of my head, try:

Code:
    .Value = Left(TextBox1.Value, 2) & "/" & Mid(TextBox1.Value, 3, 3) & "/" & Right(TextBox1.Value, 4)

The textbox doesn't see 01May2011 as a date.
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

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