Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,805
Default Type Mismatch when trying to sum columns

I did not understand why you used
'Range("R") = WorksheetFunction.Sum(Range("D"), Range("F"), _
Range("I"), Range("L"))
What does 'Range("R") represent?

Try

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"))
..Cells(lRow, "R") = WorksheetFunction.Sum(.Cells(lRow, "B"), _
..Cells(lRow, "D"), .Cells(lRow, "F"), .Cells(lRow, "L"))
End If

Next lRow

End With

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

End Sub


"jeremiah" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Type Mismatch when trying to sum columns


If .Cells(lRow, "B").Value < "Year To Date" Then
Cells(lRow, "R").Value = WorksheetFunction.Sum(Cells(lRow, "D").Value, _
Cells(lRow, "F").Value, Cells(lRow, "I").Value, Cells(lRow, "L").Value)
End If
--
Jim Cone
Portland, Oregon USA


"jeremiah"
wrote in message
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
-snip-
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Type Mismatch when trying to sum columns

I not a vb expert by any means so I pick up alot of stuff from this forum and
others. I had read somewhere that you could use Range with
worksheetfunctions so gave it a try. None of my other attempts had worked
either so after a day of experimentation I decided to ask for help.

I have copied your sub below and do get some totals in the correct column
but on rows that shouldn't have any and they don't appear to be correct
totals. Will have to review to see what I am missing. Thanks for your help.



"Sheeloo" wrote:

I did not understand why you used
'Range("R") = WorksheetFunction.Sum(Range("D"), Range("F"), _
Range("I"), Range("L"))
What does 'Range("R") represent?

Try

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"))
.Cells(lRow, "R") = WorksheetFunction.Sum(.Cells(lRow, "B"), _
.Cells(lRow, "D"), .Cells(lRow, "F"), .Cells(lRow, "L"))
End If

Next lRow

End With

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

End Sub


"jeremiah" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Type Mismatch when trying to sum columns

With this sub I get "Unable to get sum property of the worksheetfunction class.

"Jim Cone" wrote:


If .Cells(lRow, "B").Value < "Year To Date" Then
Cells(lRow, "R").Value = WorksheetFunction.Sum(Cells(lRow, "D").Value, _
Cells(lRow, "F").Value, Cells(lRow, "I").Value, Cells(lRow, "L").Value)
End If
--
Jim Cone
Portland, Oregon USA


"jeremiah"
wrote in message
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
-snip-



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Type Mismatch when trying to sum columns

I figured it out...I had value < "Year to date" it should have been = "Year
to Date" so I was pulling the wrong rows. Thanks again.

"jeremiah" wrote:

I not a vb expert by any means so I pick up alot of stuff from this forum and
others. I had read somewhere that you could use Range with
worksheetfunctions so gave it a try. None of my other attempts had worked
either so after a day of experimentation I decided to ask for help.

I have copied your sub below and do get some totals in the correct column
but on rows that shouldn't have any and they don't appear to be correct
totals. Will have to review to see what I am missing. Thanks for your help.



"Sheeloo" wrote:

I did not understand why you used
'Range("R") = WorksheetFunction.Sum(Range("D"), Range("F"), _
Range("I"), Range("L"))
What does 'Range("R") represent?

Try

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"))
.Cells(lRow, "R") = WorksheetFunction.Sum(.Cells(lRow, "B"), _
.Cells(lRow, "D"), .Cells(lRow, "F"), .Cells(lRow, "L"))
End If

Next lRow

End With

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

End Sub


"jeremiah" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why type mismatch? davegb Excel Programming 0 April 25th 07 06:10 PM
Type Mismatch: array or user defined type expected ExcelMonkey Excel Programming 4 July 6th 06 03:40 PM
Type mismatch using rnge as Range with Type 8 Input Box STEVE BELL Excel Programming 11 December 3rd 05 05:02 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Type mismatch teresa Excel Programming 1 December 14th 04 11:19 PM


All times are GMT +1. The time now is 12:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"