Consulting

Results 1 to 6 of 6

Thread: Solved: Type mismatch "rumtime error 13"

  1. #1
    VBAX Regular
    Joined
    Apr 2010
    Posts
    46
    Location

    Solved: Type mismatch "rumtime error 13"

    Hello,

    I am getting an error when I´m trying to check on a range of cells. Does anyone knows what I´m doing wrong ?

    Here is the line where I get the error.

    [vba]If ActiveWorkbook.Worksheets(1).Range("L30:L38").Value <> 0 And ActiveWorkbook.Worksheets(1).Range("L40:L49").Value = 0 Then[/vba]

    Thanks in advance.
    /Birch81

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Should you not be testing the value in each cell within the ranges to ascertain if any of them "<> 0"?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Regular
    Joined
    Apr 2010
    Posts
    46
    Location
    Well I actualy want to see if the sum of the range differs from 0.
    but is there a smarter way of doing this?
    /Birch81

  4. #4
    VBAX Regular
    Joined
    Apr 2010
    Posts
    46
    Location
    I solved it in another way.

    [VBA]Private Function RangeValue(range As range) As Boolean

    Dim ActiveRows As Integer
    ActiveRows = 0

    For i = 0 To range.Rows.Count 'Counts Active Rows

    If range.Cells(i, 1).Value <> "" Then
    ActiveRows = ActiveRows + 1
    Else
    ActiveRows = ActiveRows
    End If
    Next

    If ActiveRows <> 0 Then
    RangeValue = True
    Else
    RangeValue = False
    End If

    End Function[/VBA]
    /Birch81

  5. #5
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Have you tried SUM?

        If Application.Sum(ThisWorkbook.Worksheets(1).Range("L30:L38").Value) <> 0 _
        And Application.Sum(ThisWorkbook.Worksheets(1).Range("L40:L49").Value) = 0 Then
            MsgBox "Yea!"
        End If

  6. #6
    VBAX Regular
    Joined
    Apr 2010
    Posts
    46
    Location
    Ahh didn´t know I could do it in that way.

    Thanks
    /Birch81

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •