PC Review


Reply
Thread Tools Rate Thread

Complex Summation

 
 
Brian
Guest
Posts: n/a
 
      16th Jun 2008
Hello

I have a workbook where the first worksheet contains building information
(i.e. square footage). Every worksheet after that is specific to an
improvement that can be made to a building such as Air Handlers would be one
worksheet and under that we list all the Air Handler work that has been done
on all the projects. I use a cross-refererence to get information such as
cost/sf and air handlers per square foot for each project. The last sheet
I'm going to use as a random total, where a user can enter several criteria
options and display the results in a cell.

Now to the question. Let's say Joe does work on Air Handlers for Building
A, B, and C. How do I write a macro that looks up Joe (on
Worksheets("Total").Range("A1")), then look up in the Air Handlers worksheet
which buildings Joe has done Air Handler work on, then use that information
to add all the square footage from the Building Information worksheet. Then
place it in Worksheets("Total").Range("B1").

Hope that makes sense
--
Brian
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      16th Jun 2008
There are a numbr a ways of doing this using filters. Below is a more
straight foreward approach.

You probably need to make the following changes

1) The Rows where the data starts. I used Row 1
2) The names of the worksheet. I just picked names.
3) The correct columns for the data. I used columns A and B.



Sub GetTotals()

BuildingTotal = 0
With Sheets("Total")
Employee = .Range("A1")
End With
With Sheets("Air Handlers")
AirRowCount = 1
Do While .Range("A" & AirRowCount) <> ""
Worker = .Range("A" & AirRowCount)
If Worker = Employee Then
Building = .Range("B" & AirRowCount)
With Sheets("Building Information")
BuildRowCount = 1
Do While .Range("A" & BuildRowCount) <> ""
BuildingName = .Range("A" & BuildRowCount)
If BuildingName = Building Then
BuildingTotal = BuildingTotal + _
.Range("B" & BuildRowCount)
End If
BuildRowCount = BuildRowCount + 1
Loop
End With
End If
AirRowCount = AirRowCount + 1
Loop

End With
Worksheets("Total").Range("B1") = BuildingTotal

End Sub


"Brian" wrote:

> Hello
>
> I have a workbook where the first worksheet contains building information
> (i.e. square footage). Every worksheet after that is specific to an
> improvement that can be made to a building such as Air Handlers would be one
> worksheet and under that we list all the Air Handler work that has been done
> on all the projects. I use a cross-refererence to get information such as
> cost/sf and air handlers per square foot for each project. The last sheet
> I'm going to use as a random total, where a user can enter several criteria
> options and display the results in a cell.
>
> Now to the question. Let's say Joe does work on Air Handlers for Building
> A, B, and C. How do I write a macro that looks up Joe (on
> Worksheets("Total").Range("A1")), then look up in the Air Handlers worksheet
> which buildings Joe has done Air Handler work on, then use that information
> to add all the square footage from the Building Information worksheet. Then
> place it in Worksheets("Total").Range("B1").
>
> Hope that makes sense
> --
> Brian

 
Reply With Quote
 
Brian
Guest
Posts: n/a
 
      16th Jun 2008
Thanks for the help Joel, but I started working more at it and I got:


Dim lResult As Long, strManager As String, strBuilding As String, lsqft As
Long
Dim rFind As Range

strManager = Worksheets("Total").Range("C6").Value

lResult = 0

For count1 = 2 To 17
If Worksheets("Total").Range("C8").Value = "QTY" Then
For count2 = 3 To 503
If Worksheets(count1).Range("B" & count2).Value = strManager
Then
lResult = lResult + Worksheets(count1).Cells(count2,
5).Value
End If
Next count2
End If

If Worksheets("Total").Range("C8").Value = "Square Feet" Then
For count3 = 3 To 503
If Worksheets(count1).Range("B" & count3).Value = strManager
Then
strBuilding = Worksheets(count1).Range("C" & count3).Value
Set rFind =
Worksheets("BuildingList").Range("B:B").Find(strBuilding)
lResult = lResult + Worksheets("BuildingList").Range("D"
& rFind.Row).Value
End If
Next count3
End If
Next count1

Calculate:
Worksheets("Total").Range("H11").Value = lResult


End Sub


The one problem that I'm running into is that lets say I have a building
named "House" and one named "Warehouse," if the guy did both of them and
"Warehouse" is above "House" then "Warehouse" data is returned twice and
"House" is not returned. How do I get specific values?

Thanks
--
Brian


"Joel" wrote:

> There are a numbr a ways of doing this using filters. Below is a more
> straight foreward approach.
>
> You probably need to make the following changes
>
> 1) The Rows where the data starts. I used Row 1
> 2) The names of the worksheet. I just picked names.
> 3) The correct columns for the data. I used columns A and B.
>
>
>
> Sub GetTotals()
>
> BuildingTotal = 0
> With Sheets("Total")
> Employee = .Range("A1")
> End With
> With Sheets("Air Handlers")
> AirRowCount = 1
> Do While .Range("A" & AirRowCount) <> ""
> Worker = .Range("A" & AirRowCount)
> If Worker = Employee Then
> Building = .Range("B" & AirRowCount)
> With Sheets("Building Information")
> BuildRowCount = 1
> Do While .Range("A" & BuildRowCount) <> ""
> BuildingName = .Range("A" & BuildRowCount)
> If BuildingName = Building Then
> BuildingTotal = BuildingTotal + _
> .Range("B" & BuildRowCount)
> End If
> BuildRowCount = BuildRowCount + 1
> Loop
> End With
> End If
> AirRowCount = AirRowCount + 1
> Loop
>
> End With
> Worksheets("Total").Range("B1") = BuildingTotal
>
> End Sub
>
>
> "Brian" wrote:
>
> > Hello
> >
> > I have a workbook where the first worksheet contains building information
> > (i.e. square footage). Every worksheet after that is specific to an
> > improvement that can be made to a building such as Air Handlers would be one
> > worksheet and under that we list all the Air Handler work that has been done
> > on all the projects. I use a cross-refererence to get information such as
> > cost/sf and air handlers per square foot for each project. The last sheet
> > I'm going to use as a random total, where a user can enter several criteria
> > options and display the results in a cell.
> >
> > Now to the question. Let's say Joe does work on Air Handlers for Building
> > A, B, and C. How do I write a macro that looks up Joe (on
> > Worksheets("Total").Range("A1")), then look up in the Air Handlers worksheet
> > which buildings Joe has done Air Handler work on, then use that information
> > to add all the square footage from the Building Information worksheet. Then
> > place it in Worksheets("Total").Range("B1").
> >
> > Hope that makes sense
> > --
> > Brian

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      16th Jun 2008
from
Worksheets("BuildingList").Range("B:B").Find(strBuilding)
to
Worksheets("BuildingList").Range("B:B").Find(what:=strBuilding, _
lookin:=xlvalues,lookat:=xlwhole)


"Brian" wrote:

> Thanks for the help Joel, but I started working more at it and I got:
>
>
> Dim lResult As Long, strManager As String, strBuilding As String, lsqft As
> Long
> Dim rFind As Range
>
> strManager = Worksheets("Total").Range("C6").Value
>
> lResult = 0
>
> For count1 = 2 To 17
> If Worksheets("Total").Range("C8").Value = "QTY" Then
> For count2 = 3 To 503
> If Worksheets(count1).Range("B" & count2).Value = strManager
> Then
> lResult = lResult + Worksheets(count1).Cells(count2,
> 5).Value
> End If
> Next count2
> End If
>
> If Worksheets("Total").Range("C8").Value = "Square Feet" Then
> For count3 = 3 To 503
> If Worksheets(count1).Range("B" & count3).Value = strManager
> Then
> strBuilding = Worksheets(count1).Range("C" & count3).Value
> Set rFind =
> Worksheets("BuildingList").Range("B:B").Find(strBuilding)
> lResult = lResult + Worksheets("BuildingList").Range("D"
> & rFind.Row).Value
> End If
> Next count3
> End If
> Next count1
>
> Calculate:
> Worksheets("Total").Range("H11").Value = lResult
>
>
> End Sub
>
>
> The one problem that I'm running into is that lets say I have a building
> named "House" and one named "Warehouse," if the guy did both of them and
> "Warehouse" is above "House" then "Warehouse" data is returned twice and
> "House" is not returned. How do I get specific values?
>
> Thanks
> --
> Brian
>
>
> "Joel" wrote:
>
> > There are a numbr a ways of doing this using filters. Below is a more
> > straight foreward approach.
> >
> > You probably need to make the following changes
> >
> > 1) The Rows where the data starts. I used Row 1
> > 2) The names of the worksheet. I just picked names.
> > 3) The correct columns for the data. I used columns A and B.
> >
> >
> >
> > Sub GetTotals()
> >
> > BuildingTotal = 0
> > With Sheets("Total")
> > Employee = .Range("A1")
> > End With
> > With Sheets("Air Handlers")
> > AirRowCount = 1
> > Do While .Range("A" & AirRowCount) <> ""
> > Worker = .Range("A" & AirRowCount)
> > If Worker = Employee Then
> > Building = .Range("B" & AirRowCount)
> > With Sheets("Building Information")
> > BuildRowCount = 1
> > Do While .Range("A" & BuildRowCount) <> ""
> > BuildingName = .Range("A" & BuildRowCount)
> > If BuildingName = Building Then
> > BuildingTotal = BuildingTotal + _
> > .Range("B" & BuildRowCount)
> > End If
> > BuildRowCount = BuildRowCount + 1
> > Loop
> > End With
> > End If
> > AirRowCount = AirRowCount + 1
> > Loop
> >
> > End With
> > Worksheets("Total").Range("B1") = BuildingTotal
> >
> > End Sub
> >
> >
> > "Brian" wrote:
> >
> > > Hello
> > >
> > > I have a workbook where the first worksheet contains building information
> > > (i.e. square footage). Every worksheet after that is specific to an
> > > improvement that can be made to a building such as Air Handlers would be one
> > > worksheet and under that we list all the Air Handler work that has been done
> > > on all the projects. I use a cross-refererence to get information such as
> > > cost/sf and air handlers per square foot for each project. The last sheet
> > > I'm going to use as a random total, where a user can enter several criteria
> > > options and display the results in a cell.
> > >
> > > Now to the question. Let's say Joe does work on Air Handlers for Building
> > > A, B, and C. How do I write a macro that looks up Joe (on
> > > Worksheets("Total").Range("A1")), then look up in the Air Handlers worksheet
> > > which buildings Joe has done Air Handler work on, then use that information
> > > to add all the square footage from the Building Information worksheet. Then
> > > place it in Worksheets("Total").Range("B1").
> > >
> > > Hope that makes sense
> > > --
> > > Brian

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
complex color fill conditions- if statements or complex formula? lilly8008 Microsoft Excel Misc 1 18th Dec 2009 04:57 AM
Complex Index Match Help (or at least complex to me) Jennifer Reitman Microsoft Excel Misc 3 10th Aug 2006 08:51 PM
Using toggle buttons in a complex query (complex for me, at least) =?Utf-8?B?QmlsbHk=?= Microsoft Access Forms 4 23rd Jun 2005 02:08 AM
VBA code to perform summation and product summation 21MSU Microsoft Excel Programming 4 17th May 2004 07:19 PM
Help!!! how to make a complex form for input? (at least I think it is complex...) tsangwi Microsoft Access Forms 0 22nd Nov 2003 02:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:18 PM.