Runtime Error 13 - Mismatch

M

Mike C

Below is the code I am using. The code is designed to hide zeros. Let me
know if anyone has any ideas or suggestions why it is not working. Thanks in
advance.
Mike C

Sub Toggle_Suppresion()

Dim i As Integer
Dim n As Integer
Dim wkb As Workbook
Dim wks As Worksheet
Dim fim As Worksheet
Dim rng As Range
Dim absRowTot As Double
Dim topCell As Integer 'The first Row in the report with data (must be
changed accordingly)
Dim bottomCell As Integer 'Bottom Row in the report (set automatically)
Dim absRowTotColumn 'The numeric column that has the absolute value
sumation


topCell = 8
bottomCell = ActiveSheet.UsedRange.Rows.Count
absRowTotColumn = 20

Set wks = ActiveCell.Worksheet
Set fim = ActiveSheet

Application.ScreenUpdating = False

'fim.Select
'Rows(topCell & ":" & bottomCell).Select
'Selection.EntireRow.Hidden = False


For i = topCell To bottomCell Step 1
absRowTot = fim.Cells(i, absRowTotColumn).Value


If absRowTot = 0 Then

For n = i To (i)
Rows(n).Select
Selection.EntireRow.Hidden = True
Next
End If
Next

fim.Select
Range("a1").Select

Application.ScreenUpdating = True


End Sub
 
J

Jim Thomlinson

absRowTot is of type double. If you try to assign text to that variable you
will get a type mismatch. Change it to type Variant as a quick and dirty
solution.
 
D

Dave Peterson

Another question...

Are there any errors in that range (column 20)?

If yes, you could use:
For i = topCell To bottomCell Step 1
if iserror(fim.cells(i,absrowtotcolumn).value) then
'skip it
else
'absrowtot is still declared a variant
absRowTot = fim.Cells(i, absRowTotColumn).Value
If absRowTot = 0 Then
For n = i To i
fim.Rows(n).Hidden = True
Next n
End If end if
Next i

Ps. I would never use "as integer" in the declarations. I use "as long". They
hold bigger numbers (less change of problems) and from what I've read are
quicker on new pcs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top