Run-time error 13 - Type mismatch

skyking

Board Regular
Joined
Jul 10, 2010
Messages
52
Dear all,

Can you help to fix the Run-time error for the VBA?

When I step into the VBA code and it pops up a message box at the red line below with "Run-time error 13 - Type mismatch". Can you help?

Private Sub CommandNextMonth_Click()
Dim val As String
Dim LR As Range
Dim a As Range
Dim val2 As Date
Cells(72, "H") = Date 'Set Last Access Day to Current Day
val = Cells(72, "J") 'Set to End Day (Last Month)
Debug.Print val
val2 = CDate(val) 'Change val to calculable
Debug.Print val2
For Each a In Range("A53:A100")
Debug.Print a.Address
Set a = ActiveWorkbook.Sheets(1).Range("A53:A53")
If a = "" Then Exit For
If a.Value < val2 Then
Debug.Print a.Address, a.Value, val2
Application.GoTo a, True
a.EntireRow.Delete xlNone
End If
Next
CommandNextMonth.Enabled = False
CommandPreviousMonth.Enabled = True
Application.Calculate
End Sub

Your early reponse is much appreciate.

Regards,
Wky King
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Ive just run this and dont seem to get a problem if there is a date in J72
what do you have there?
 
Upvote 0
As it mention at the end of the red line.
J72 should be the end day of previous month (eg. 31/03/2011).
Will you please input it to J72 and re-run the code to get same result?
 
Upvote 0
so you are looking for that line of code to generate the last day of the month prior to H72?
 
Upvote 0
No, I suppose to get the cell value to "val".
(ie val = Cells(72, "J").Content OR val = Cells(72, "J").value)
That means val should be 31/3/2011.
 
Upvote 0
Complementing previous post

Immediate Window
31/03/2011
31/03/2011
$A$53

M.
 
Upvote 0
Marcelo,

I don't understand what you mean by "With J72 = 31/03/2011 it worked perfect for me also".
Did you copy my code and run it yourself with J72 = 31/03/2011?
Anyway, I still get that run-time error 13: Type mismatch message box pops up.
 
Upvote 0
Marcelo,

I don't understand what you mean by "With J72 = 31/03/2011 it worked perfect for me also".
Did you copy my code and run it yourself with J72 = 31/03/2011?
Anyway, I still get that run-time error 13: Type mismatch message box pops up.

I just typed 31/03/2011 in J72 and run the macro.

Yes, i have just copied your code, exactly as it is, and it worked fine for me. No error.

M.
 
Upvote 0
I believe that you are getting the error when the cell J72 is empty. If the J72 is having some date , the code will work fine. If not can you check what is the value in J72, when the error is thrown?

Thanks,

Ogo
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,879
Members
452,948
Latest member
Dupuhini

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