Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default sum matrix cells based on value in a separate cell

I have a project table to record time worked on projects each day
DayOfWeek: contains the number of hours worked on SUN, MON ...
SET: contains the Project Id

NAME | SUN | SET | MON | SET ...
--------|-------|------|-------|-------
John | 8 | set1 | 8 | set2
Jane | 10 | set3 | 8 | set2

Is it possible In VBA (or Excel spreadsheet) to produce this result
SET | TOTAL
------|---------
set1 | 8
set2 | 16
set3 | 10
...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default sum matrix cells based on value in a separate cell

Hi,
Give this a try:

Sub TotalProjectTimes()

Dim lastrow As Long, r As Long, c As Integer, idx As Integer
Dim v() As Variant, ProjSum() As Double
Dim res
Dim ws1 As Worksheet

Set ws1 = Worksheets("sheet1")

ReDim v(1 To 1)
n = 0

With ws1
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row

For r = 2 To lastrow

For c = 3 To 15 Step 2 ' Loop through project IDs for each day
(Sunday to Saturday)
If .Cells(r, c) < "" Then
res = Application.Match(.Cells(r, c), v, 0) 'Match against
stored project IDs
If IsError(res) Then ' new project ID
' redimension arrays ....
n = n + 1
ReDim Preserve ProjSum(1 To n)
ReDim Preserve v(1 To n)
v(n) = .Cells(r, c) ' Store project ID
idx = n
Else
idx = res
End If
ProjSum(idx) = ProjSum(idx) + .Cells(r, c - 1) ' Summ times
for this project
End If
Next c

Next r

End With

' List Project Ids and associated times
For i = 1 To UBound(v)
Debug.Print v(i), ProjSum(i)
Next i

End Sub


"excelman" wrote:

I have a project table to record time worked on projects each day
DayOfWeek: contains the number of hours worked on SUN, MON ...
SET: contains the Project Id

NAME | SUN | SET | MON | SET ...
--------|-------|------|-------|-------
John | 8 | set1 | 8 | set2
Jane | 10 | set3 | 8 | set2

Is it possible In VBA (or Excel spreadsheet) to produce this result
SET | TOTAL
------|---------
set1 | 8
set2 | 16
set3 | 10
...

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
separate one cell into several cells martin whiting Excel Discussion (Misc queries) 2 April 16th 09 05:33 PM
Insert a value in a cell based upon a comparison of cell values in 2 separate worksheets Doctorjones_md Excel Discussion (Misc queries) 7 June 8th 07 09:32 PM
Insert a value in a cell based upon a comparison of cell values in 2 separate worksheets Doctorjones_md Excel Worksheet Functions 7 June 8th 07 09:32 PM
Separate first and second name in one cell into separate cells. Dwight in Georgia Excel Discussion (Misc queries) 3 January 25th 06 09:09 PM
Separate first and second name in one cell into separate cells. Gary's Student Excel Discussion (Misc queries) 0 April 27th 05 11:11 PM


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