Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default using the cells property for use with Application.WorksheetFunction.Sum

Has anyone had any success with using the Cells Propery when using the
Application.WorksheetFunction.Sum function? My code is below:

Sub AddDataMorningMil(mon As String, Day As String, yr As String,
intDOW As Integer) 'DOW = Day of Week
Dim x As Integer, row As Integer, colStart As Integer, colEnd As
Integer, varSum As Variant

' -- Friday column & starting row
colEnd = 6
row = 15

' -- Get the start column & row
Select Case intDOW
Case 2 'Monday
colStart = 2
Case 3 'TuesDay
colStart = 3
Case 4 'WednesDay
colStart = 4
Case 5 'ThursDay
colStart = 5
Case 6 'FriDay
colStart = 6
Case Else
colStart = 2
End Select

Sheets("Monthly_Summary").Select
x = 1

Do
If Cells(row, colStart).value < "" Then
col = col + 1
Else
Exit Do
End If
Loop

Sheets(mon & "_" & Day & "_" & yr).Select
Cells(row, colStart).Select
varSum = Application.WorksheetFunction.Sum(Range(Cells(row,
colStart) & ":" & Cells(row, colEnd))) 'bombs here
varSum = Format(varSum, "hh:mm:ss")
Worksheets("Monthly_Summary").Select
Cells(row, 2).Select
ActiveCell.value = varSum
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default using the cells property for use withApplication.WorksheetFunction.Sum

Try:

varSum = Application.WorksheetFunction _
.Sum(Range(Cells(row,colStart),Cells(row, colEnd)))



EAB1977 wrote:

Has anyone had any success with using the Cells Propery when using the
Application.WorksheetFunction.Sum function? My code is below:

Sub AddDataMorningMil(mon As String, Day As String, yr As String,
intDOW As Integer) 'DOW = Day of Week
Dim x As Integer, row As Integer, colStart As Integer, colEnd As
Integer, varSum As Variant

' -- Friday column & starting row
colEnd = 6
row = 15

' -- Get the start column & row
Select Case intDOW
Case 2 'Monday
colStart = 2
Case 3 'TuesDay
colStart = 3
Case 4 'WednesDay
colStart = 4
Case 5 'ThursDay
colStart = 5
Case 6 'FriDay
colStart = 6
Case Else
colStart = 2
End Select

Sheets("Monthly_Summary").Select
x = 1

Do
If Cells(row, colStart).value < "" Then
col = col + 1
Else
Exit Do
End If
Loop

Sheets(mon & "_" & Day & "_" & yr).Select
Cells(row, colStart).Select
varSum = Application.WorksheetFunction.Sum(Range(Cells(row,
colStart) & ":" & Cells(row, colEnd))) 'bombs here
varSum = Format(varSum, "hh:mm:ss")
Worksheets("Monthly_Summary").Select
Cells(row, 2).Select
ActiveCell.value = varSum
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default using the cells property for use with Application.WorksheetFunction.Sum

varSum = Application.WorksheetFunction.Sum(Range(Cells(row,
colStart) & ":" & Cells(row, colEnd))) 'bombs here

Syntax should be:

varSum = Application.WorksheetFunction.Sum(Range(Cells(row,
colStart), Cells(row, colEnd)))

Without the Cells property being specifically qualified, the method will
apply only to the active sheet, which appears to be: Sheets(mon & "_" & Day
& "_" & yr).Select

If it were my code, I would put the sheet in a variable like:

Dim sh As Worksheet
Set sh = Sheets(mon & "_" & Day & "_" & yr)
varSum = Application.WorksheetFunction. _
Sum(Range(sh.Cells(row, colStart), sh.Cells(row, colEnd)))



"EAB1977" wrote in message
...
Has anyone had any success with using the Cells Propery when using the
Application.WorksheetFunction.Sum function? My code is below:

Sub AddDataMorningMil(mon As String, Day As String, yr As String,
intDOW As Integer) 'DOW = Day of Week
Dim x As Integer, row As Integer, colStart As Integer, colEnd As
Integer, varSum As Variant

' -- Friday column & starting row
colEnd = 6
row = 15

' -- Get the start column & row
Select Case intDOW
Case 2 'Monday
colStart = 2
Case 3 'TuesDay
colStart = 3
Case 4 'WednesDay
colStart = 4
Case 5 'ThursDay
colStart = 5
Case 6 'FriDay
colStart = 6
Case Else
colStart = 2
End Select

Sheets("Monthly_Summary").Select
x = 1

Do
If Cells(row, colStart).value < "" Then
col = col + 1
Else
Exit Do
End If
Loop

Sheets(mon & "_" & Day & "_" & yr).Select
Cells(row, colStart).Select
varSum = Application.WorksheetFunction.Sum(Range(Cells(row,
colStart) & ":" & Cells(row, colEnd))) 'bombs here
varSum = Format(varSum, "hh:mm:ss")
Worksheets("Monthly_Summary").Select
Cells(row, 2).Select
ActiveCell.value = varSum
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
unable to get match property of WorksheetFunction class titus Excel Programming 3 September 6th 06 12:41 AM
Unable to get Match property of the WorksheetFunction class C++User Excel Programming 8 May 3rd 06 02:54 PM
Unable to get Match property of worksheetfunction Kevin Vaughn Excel Programming 4 March 17th 06 12:40 AM
Unable to get the Text property of the WorksheetFunction class John[_86_] Excel Programming 5 November 25th 04 01:40 AM
Unable to get the Vlookup Property of the WorkSheetFunction Class monagan Excel Programming 2 August 3rd 04 09:32 PM


All times are GMT +1. The time now is 05:00 AM.

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

About Us

"It's about Microsoft Excel"