Run-Time error '13': Type Mismatch

Risk

Board Regular
Joined
Jul 27, 2006
Messages
71
Hi I'm trying to convert all text '0 to numbers while skipping '00, percents, formulas, etc..

I'm using the code below but I keep getting "Run-Time error '13': Type Mismatch"

Any ideas what I'm doing wrong or how to fix?

Code:
Sub TextToNumber()

    Dim x As Worksheet, z As Range
               
       For Each x In Worksheets
            Sheets(x.Name).Activate
            Range("a1").Select
            ActiveCell.SpecialCells(xlLastCell).Select
            LastCell = ActiveCell.Address
            Range("a1:" & LastCell).Select
                        
            For Each z In Selection
               If Not IsEmpty(z) _
               And Len(z.Value) = 1 _
               And Application.IsText(z) _
               And IsNumeric(z.Value) _
               And Not z.HasFormula _
               And Not Left(z.Value, 2) = "0." _
               And Left(z.Value, 1) = "0" Then
                    z.Value = z.Value
                    z.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""_);_(@_)"
               End If
            Next z
            
            Range("a1").Select
        
        Next x
    
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Risk

Board Regular
Joined
Jul 27, 2006
Messages
71
It debugs at

Code:
And Left(z.Value, 1) = "0" Then

but it doesn't always debug; only with certain report that I have, but I'm unable to determine the cause.
 
Upvote 0

Risk

Board Regular
Joined
Jul 27, 2006
Messages
71
Ok I think I found the problem. It was getting the runtime error on formulas which needed CSE reapplied.

Interesting.
 
Upvote 0

Forum statistics

Threads
1,190,836
Messages
5,983,166
Members
439,824
Latest member
jr599

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
Top