PDA

View Full Version : Solved: Type mismatch "rumtime error 13"



Birch81
09-20-2010, 02:04 PM
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.

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

Thanks in advance.

Aussiebear
09-20-2010, 03:55 PM
Should you not be testing the value in each cell within the ranges to ascertain if any of them "<> 0"?

Birch81
09-21-2010, 01:12 AM
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
09-21-2010, 03:45 AM
I solved it in another way.

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

GTO
09-21-2010, 03:46 AM
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

Birch81
09-22-2010, 03:29 AM
Ahh didn´t know I could do it in that way.

Thanks