Runtime Error 13- VBA

bloodybrit90

Board Regular
Joined
Jul 18, 2011
Messages
111
The following macro works for worksheet with approx. 20,000 rows, however when I use this on a workshhet with approx. 95,000 rows I receive runtime error 13 (type mismatch). Could this be written in a better way?...Any advise?

Sub Formatcorrectly()
Dim I As Object
Application.ScreenUpdating = False
For Each I In ActiveSheet.UsedRange
I = I.Value
Next I
Application.ScreenUpdating = True
Dim c As Range
Application.ScreenUpdating = False
For Each c In Range("AA2:AA" & Cells(Rows.Count, "AA").End(xlUp).Row)
c.Value = DateSerial(Left(c.Value, 4), Mid(c.Value, 5, 2), Right(c.Value, 2))
c.NumberFormat = "mm/dd/yyyy"
Next
Application.ScreenUpdating = False
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Probably in column AA in a row there is a cell with letters or spaces so Left(c.Value, 4) returns "ABCD" that is not a valid number.
What I do is when I get the error I will click debug and point the cursor on c.Value to see what does it hold, what is the value of c.Value
You can avoid errors by checking contents of c.Value before applying to DateSerial
Cheers
Sergio
 
Upvote 0

Forum statistics

Threads
1,215,328
Messages
6,124,295
Members
449,149
Latest member
mwdbActuary

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