Correcting Run-time error '13' Type Mismatch

Livin404

Well-known Member
Joined
Jan 7, 2019
Messages
774
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,

I've been working on a code to get my Database in Descending Order. The one I currently have actually works, but then I get my "Run-Time error '13'. From what I read it tells me the code does not recognise Column A beginning at A2 as a Date.

VBA Code:
Private Sub CmdDescend_Click()
Dim xlSort As XlSortOrder
Dim LastRow As Long
With Sheets("ACTIVITY")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("A2") = "Date"
.Columns("A:F").Sort key1:=.Range("A2"), order1:=xlDescending, Header:=xlYes
Call Submit
Call RESET
End With
End Sub


When I select the Debug it goes to a completely different Macro.

It highlights
Excel Formula:
.Cells(iRow, 1).Value = CDate(frmForm.Txtdate)

For full context here is the full Macro. I do not want to change that because it works well for my other tasks I have.

VBA Code:
Sub Submit()
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("Activity")
If frmForm.txtRowNumber.Value = "" Then
iRow = [Counta(Activity!A:A)] + 1
Else
iRow = frmForm.txtRowNumber.Value
End If
With sh
      .Cells(iRow, 1).Value = CDate(frmForm.Txtdate)
     .Cells(iRow, 2) = frmForm.Txtmission.Value
     .Cells(iRow, 3) = frmForm.Cmbmode.Value
     .Cells(iRow, 4) = frmForm.Cmbdenton_fms.Value
     .Cells(iRow, 5) = frmForm.Txtweight.Value
        End With
End Sub

Thank you,
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Should this:
VBA Code:
.Cells(iRow, 1).Value = CDate(frmForm.Txtdate)
Be:
VBA Code:
.Cells(iRow, 1).Value = CDate(frmForm.Txtdate.Text)
 
Upvote 0
Should this:
VBA Code:
.Cells(iRow, 1).Value = CDate(frmForm.Txtdate)
Be:
VBA Code:
.Cells(iRow, 1).Value = CDate(frmForm.Txtdate.Text)
I did try it and I'm afraid I'm getting the same result. Thank you for the input.
 
Upvote 0
I got it sorted. I used
Excel Formula:
 If frmForm.Txtdate <> "" Then .Cells(iRow, 1).Value = CDate(frmForm.Txtdate)
for that line it is wonderful
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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