LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Generate Subtotal Summary from Sheet1 into Sheet2

Within the same workbook, I want to summarize
by Project the "Detail" worksheet into the "Summary" worksheet.
I probably have a range syntax error, but I cannot detect it.
I have an Overflow error and the Countif that drives the loop is at
zero.
..
I could easily do it with a pivot table, that is not what I want.
I want to process it with VBA as I have attempted below.
Help appreciated.
J.P.
.............................................
Source : "Detail" worksheet
A B C D
E
1. Date Project Activity Force Hours
2. 8/27/2010 Project C T 5 300
3. 8/29/2010 Project C U 10 500
4. 8/26/2010 Project A L 1 50
5. 8/28/2010 Project A M 11 550
6. 8/23/2010 Project K V 4 200
7. 8/25/2010 Project K X 6 300
...........................................
Destination : "Destination" worksheet
Project Force Hours
Project A 12 600
Project C 15 800
Project K 10 500
...........................................
Sub ProjectSummary()
Dim WB As Workbook
Dim SH1 As Worksheet
Dim SH2 As Worksheet
Dim MyPath, Line As String
Dim DestCell As Range
Dim i As Integer: Dim j As Integer: Dim k As Integer
Dim RngD As Range
Dim RngE As Range
Dim RngB As Range
On Error GoTo ErrorCatch
MyPath = "C:\1-Work\TestData\"
Set WB = Workbooks.Open(MyPath & "Omega.xls")
Set SH1 = WB.Worksheets("Detail")
Set SH2 = WB.Worksheets("Summary")
Set DestCell = SH2.Range("A1")
ActiveWorkbook.Sheets("Detail").Select
DestCell = "Project"
DestCell.Offset(0, 1) = "Force"
DestCell.Offset(0, 2) = "Hours"
'------------------------------------------
'Sort rows by Project
SH1.Range("A2").CurrentRegion.Sort Key1:=SH1.Range("B2"),
Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1,
MatchCase:=False, Orientation:=xlTopToBottom
'=================== Probable Error Area =========================
Set RngD = Range(Cells(1, "D"), Cells(Rows.Count, "D").End(xlUp))
Set RngE = Range(Cells(1, "E"), Cells(Rows.Count, "E").End(xlUp))
Set RngB = Range(Cells(1, "B"), Cells(Rows.Count, "B").End(xlUp))
' Calculate Sum for Project
Line = "Do While"
Do While i <= Worksheets("Detail").Range("A100").End(xlUp).Row
j = Application.CountIf(RngB, Cells(i, "B"))
Line = j & " Summary Col. A " 'Error is there : Overflow message
and J = 0
'================================================= ======
Worksheets("Summary").Cells(k, "A") = Cells(i, "B")
Worksheets("Summary").Cells(k, "B") = Application.SumIf(RngB,
Cells(i, "B"), RngD)
Worksheets("Summary").Cells(k, "C") = Application.SumIf(RngB,
Cells(i, "B"), RngE)
k = k + 1: i = i + j
Loop
Exit Sub
ErrorCatch:
MsgBox "ErrorCatch Line : " & Line & " " & Err.Description
Resume Next
End Sub
 
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
sheet2 = sheet1 DA[_2_] Excel Programming 4 April 12th 10 09:14 PM
copy data from sheet2 to sheet1 when sheet2 has variable # of rows Anne Excel Discussion (Misc queries) 6 February 27th 09 09:48 PM
A1 Sheet2 is linked to A1 sheet1 so that user enters value(abc123) a1 sheet1 and A1 sheet2 is updated pano[_3_] Excel Programming 2 October 28th 07 02:32 PM
how do copy "sheet1!A1+1 in sheet2 to sheet 3 and get "sheet2!A1+ Dany Excel Discussion (Misc queries) 5 April 16th 07 03:27 AM
[=Sheet1!A1] - if i use Column A1 ('Sheet1') / A2 ('Sheet2') Lawrence C H Tan Excel Worksheet Functions 0 January 19th 07 08:29 PM


All times are GMT +1. The time now is 09:23 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"