• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Run Type Error 13 - Data Mismatch

David Evans

Active Member
Code:
Private Sub Worksheet_Calculate()
   
    Application.ScreenUpdating = False
    Dim c As Range
    For Each c In Range("D85:AC85")
        c.EntireColumn.Hidden = (c.Value = 0)
    Next c
    Application.ScreenUpdating = True
End Sub

causes an Error 13 ...

I cannot for the life of me see it ...
Any insight gratefully received
 
Hi David,

When I run your code, this what happened:
Case 1: in row 85 from column D:AC if I put something like 1 or a, that column is not hidden.
Case 2: if the range is blank it is hidden.

Note this thing happened when i debug the code line by line.

But if I put say in D85 =D82 and change value in D82, nothing happened.

But I did not received any error.

Regards,
 
Hi David,

When I run your code, this what happened:
Case 1: in row 85 from column D:AC if I put something like 1 or a, that column is not hidden.
Case 2: if the range is blank it is hidden.

Note this thing happened when i debug the code line by line.

But if I put say in D85 =D82 and change value in D82, nothing happened.

But I did not received any error.

Regards,
Thanks for giving it a shot - IIRC, it used to work ..... in a slightly different worksheet!!
 
David

Your code works fine in my Excel 2010 and 2013 versions.

Do you have numbers of calculations in row 85?
Can you share the worksheet that isn't working?
 
David

Your code works fine in my Excel 2010 and 2013 versions.

Do you have numbers of calculations in row 85?
Can you share the worksheet that isn't working?
Thanks - you guys are on to it! -The range has formulas and *occasionally* fails!

When i get back in the office I'll post the offending worksheet - suitable redacted - so that we can all understand the root cause.
Appreciate the reply!
 
You can wrap the line code with If statement like below so that it doesn't trip on errors.:
Code:
  If IsNumeric(c.Value) Then
  c.EntireColumn.Hidden = (c.Value = 0)
  End If
 
@David Evans

Hi tried it with ISERROR: see below code.

Code:
Private Sub Worksheet_Calculate()
 
    Application.ScreenUpdating = False
    Dim c As Range
   
    For Each c In Range("D85:AC85")
        If IsError(c.Value) Then
        c.EntireColumn.Hidden = False
        Else
        c.EntireColumn.Hidden = (c.Value = 0)
        End If
       
       
    Next c
    Application.ScreenUpdating = True
End Sub

Regards,
 
Back
Top