Type Mismatch

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
I am receiving a type mismatch on the line below and am not sure how to make the correction.

Code:
If .Cells(E, 30 + D).value = "#DIV/0!" Then

The target cell at the moment of the error has "#DIV/0!" as its contents.

The line exists within a with statement:

Code:
With wkbk.Sheets("Ratios")    
        If IsError(.Cells(E, 30 + D).value) Then
        .Rows(E).Delete
        End If

        If .Cells(E, 30 + D).value = "#DIV/0!" Then
        .Rows(E).Delete
        End If


        If .Cells(E, 30 + D).value = "" Then
        .Rows(E).Delete
        End If
    
        End With

All of the variables are declared as integers. Are there other sources of potential mismatched data types?
 

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
You're first If statement should delete any rows with Div0 error, so you shouldn't get the typemismatch error.
 
Upvote 0
I reduced the section of code to what I have below:

When I run the code it doesn't appear as though the nested loops are running over all the cells that I would like them to. This is based on the clock speed of the time it takes from the beginning of this section to the point I run into a subsequent error AND the fact that the error is caused by a cell that still includes a cell value of "#DIV/0!". I'm not sure why the lines below would just be skipped over during runtime. Any ideas?

Code:
For D = 31 To B    
        For E = 4 To C
        
        If IsError(wkbk.Sheets("Ratios").Cells(E, 30 + D).value) Then
            wkbk.Sheets("Ratios").Rows(E).Delete
        End If
        
        Next E
        
    Next D
 
Upvote 0
When deleting rows you need to loop backwards (ie bottom up)
 
Upvote 0
Hi

Are the error values the result of formulas or are they constant values?
 
Last edited:
Upvote 0
I changed the rows part of the loop to step backwards, but I am still receiving the error later in the code. The errors are R1C1formula generated.

I suspect the error is caused by the formula and the way the input data is presented. I am going to copy pastevalues the entire area I would like then do the nested loop to get rid of error values.
 
Upvote 0
With the formulae in those columns try
Code:
   Range(Cells(1, 61), Cells(1, 30 + b)).EntireColumn.SpecialCells(xlFormulas, xlErrors).EntireRow.Delete
 
Upvote 0
I changed the order of operations in the script so that the cell filter runs after the cell values are pasted to a new sheet thus eliminating the formula generated error. Thanks for your help!
 
Upvote 0
Glad it's sorted & thanks for the eedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
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