View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jeremiah Jeremiah is offline
external usenet poster
 
Posts: 49
Default Type Mismatch when trying to sum columns

I am trying to sum the value in 4 numbers across the same row if the value of
another cell in that row is a specific string. I need to be able to loop
through the sheet because there are multiple rows that I will need to search
for my criteria. Using the below sub I get a typemismatch error - I assume
it is because some of my cell values may be blank - is there a way to
correct this

Sub SumHours()
Dim Firstrow As Long
Dim LastRow As Long
Dim lRow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim rng As Range
Dim rngColour As Range
Dim blnColour As Boolean
Dim Range

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet

.Select

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

.DisplayPageBreaks = False

Firstrow = 2
LastRow = .UsedRange.Rows(.UsedRange.Rows.Count).Row

For lRow = LastRow To Firstrow Step -1

If .Cells(lRow, "B").value < "Year To Date" Then
Range("R") = WorksheetFunction.Sum(Range("D"), Range("F"),
Range("I"), Range("L"))
End If

Next lRow

End With

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

End Sub