rubikscube991
Member
I was writing a code to change date in string format to date format while transferring from userform to cell.
for example 12.2.2017 would change to 12-02-2017 or
12/02.2017 would change to 12-02-2017
Code as below, but it is giving runtype error & Type mismatch errors in substitute formula. pls help. thanks a lot in advance..!!
for example 12.2.2017 would change to 12-02-2017 or
12/02.2017 would change to 12-02-2017
Code as below, but it is giving runtype error & Type mismatch errors in substitute formula. pls help. thanks a lot in advance..!!
Code:
Private Sub CommandButton1_Click()
Dim a As String
Dim b As Integer
With Application.WorksheetFunction
'a = TextBox1.Value
Sheet1.Range("R1").Value = TextBox1.Value
'MsgBox a
'##Error in this line##
b = DateValue(.Substitute(.Substitute(.Substitute(Sheet1.Range("R1").Value, Chr(46), Chr(45)), Chr(47), Chr(45)), Chr(92), Chr(45)))
MsgBox b
If IsNumeric(b) Then
Sheet1.Range("Q32000").End(xlUp).Value = b
Activecell.NumberFormat = "[$-en-IN,1]dd/mm/yy;@"
Else
MsgBox "Please enter date in dd-mm-yyyy format"
End If
End With
End Sub
Attachments
Last edited by a moderator: