Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to count items depending on attributes in VBA

Hello
I have a table
Each line is about a window and its attributes.
One of the attributes is the floor on which the window is installed and an other is the class (1-5) of the window
What I need to do is: I want to count the windows on each floor from floor 1-x and depending on its class.
So the table looks like that:


Window
Number floor class
1 1 1
2 1 1
3 2 3
4 2 3
5 2 2
.. . .
.. . .
.. . .

So the result should be :
2 Windows on floor 1 with class 1
2 Windows on floor 2 with class 3
1 Window on floor 2 with class 2
and so on...... for the other floors

in VBA

I tried the function dcount but did not succeed because the criteria should not be in the table
and I dont know how to loop it..
Dim winClass1 as long
winClass1 = Application.WorksheetFunction.DCountA(Range("A:F") , 2, Range("H1:J2"))

Thank you very much for any help!

MIchael


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default How to count items depending on attributes in VBA

=sumproduct(--(B2:B20=1),--(C2:C20=1))

gives fllor 1, class 1, adfjust for others.

You could use a table like thins on another sheet

A.......................B.........C.........D
Floor/Class........1..........2..........3
1.........1
2.........2
3.........3

and use

=sumproduct(--(Sheet1!$B$2:$B$20=$A2),--(Sheet1!$C$2:$C$20=B$1))

and copy down and across


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"MIchael" wrote in message
...
Hello
I have a table
Each line is about a window and its attributes.
One of the attributes is the floor on which the window is installed and an
other is the class (1-5) of the window
What I need to do is: I want to count the windows on each floor from floor
1-x and depending on its class.
So the table looks like that:


Window
Number floor class
1 1 1
2 1 1
3 2 3
4 2 3
5 2 2
. . .
. . .
. . .

So the result should be :
2 Windows on floor 1 with class 1
2 Windows on floor 2 with class 3
1 Window on floor 2 with class 2
and so on...... for the other floors

in VBA

I tried the function dcount but did not succeed because the criteria
should not be in the table
and I dont know how to loop it..
Dim winClass1 as long
winClass1 = Application.WorksheetFunction.DCountA(Range("A:F") , 2,
Range("H1:J2"))

Thank you very much for any help!

MIchael




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to count items depending on attributes in VBA

Thanks for your help
but I needed it for vba
but I solved it in the meanwhile
If anyone is interested:

ciao
MIchael

Dim FeSSK2erf As Long
Dim FeSSK3erf As Long
Dim FeSSK4erf As Long
Dim FeSSK5erf As Long
Dim FeSSK2geb As Long
Dim FeSSK3geb As Long
Dim FeSSK4geb As Long
Dim FeSSK5geb As Long
Dim Lufterf As Long
Dim Luftgeb As Long
Dim Stockzähler As Long
Dim Stockzähler1 As String


Stockzähler1 = "KG"
k = 1
For i = 1 To 300 'Anzahl Fenster
Workbooks("PSS-BonnBadGodesberg-Annabe-27-Rübenach.xls").Worksheets("Fensterliste").Activate
FeSSK2erf = Evaluate("sumproduct((d11:d300&z11:z300=""" & Stockzähler1 & "2"")*1)")
FeSSK3erf = Evaluate("sumproduct((d11:d300&z11:z300=""" & Stockzähler1 & "3"")*1)")
FeSSK4erf = Evaluate("sumproduct((d11:d300&z11:z300=""" & Stockzähler1 & "4"")*1)")
FeSSK5erf = Evaluate("sumproduct((d11:d300&z11:z300=""" & Stockzähler1 & "5"")*1)")
FeSSK2geb = Evaluate("sumproduct((d11:d300&z11:z300&AQ11:AQ300 =""" & Stockzähler1 & "2" & "ja"")*1)")
FeSSK3geb = Evaluate("sumproduct((d11:d300&z11:z300&AQ11:AQ300 =""" & Stockzähler1 & "3" & "ja"")*1)")
FeSSK4geb = Evaluate("sumproduct((d11:d300&z11:z300&AQ11:AQ300 =""" & Stockzähler1 & "4" & "ja"")*1)")
FeSSK5geb = Evaluate("sumproduct((d11:d300&z11:z300&AQ11:AQ300 =""" & Stockzähler1 & "5" & "ja"")*1)")
Lufterf = Evaluate("sumproduct((d11:d300&ai11:ai300=""" & Stockzähler1 & "erforderlich"")*1)")
Luftgeb = Evaluate("sumproduct((d11:d300&ai11:ai300&AQ11:AQ3 00=""" & Stockzähler1 & "erforderlich" & "ja"")*1)")

FeSSK5erf = Evaluate("sumproduct((d11:d300&z11:z300=""" & Stockzähler1 & "5"")*1)")




If Stockzähler1 = "KG" Then
Stockzähler1 = "EG"
ElseIf Stockzähler1 = "EG" Then
Stockzähler = 0
Stockzähler1 = Stockzähler + 1 & ".OG"
Stockzähler = Stockzähler + 1
Else
Stockzähler1 = Stockzähler + 1 & ".OG"
Stockzähler = Stockzähler + 1
End If
'j

Workbooks("Test.xls").Worksheets("Tabelle1").Cells (k, 10).Value = FeSSK2erf
Workbooks("Test.xls").Worksheets("Tabelle1").Cells (k, 11).Value = FeSSK3erf
Workbooks("Test.xls").Worksheets("Tabelle1").Cells (k, 12).Value = FeSSK4erf
Workbooks("Test.xls").Worksheets("Tabelle1").Cells (k, 13).Value = FeSSK5erf
Workbooks("Test.xls").Worksheets("Tabelle1").Cells (k, 15).Value = FeSSK2geb
Workbooks("Test.xls").Worksheets("Tabelle1").Cells (k, 16).Value = FeSSK3geb
Workbooks("Test.xls").Worksheets("Tabelle1").Cells (k, 17).Value = FeSSK4geb
Workbooks("Test.xls").Worksheets("Tabelle1").Cells (k, 18).Value = FeSSK5geb
Workbooks("Test.xls").Worksheets("Tabelle1").Cells (k, 14).Value = Lufterf
Workbooks("Test.xls").Worksheets("Tabelle1").Cells (k, 19).Value = Luftgeb




Next i


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
SUMPRODUCT to count items with duplicates where another column contains two defined items PCLIVE Excel Worksheet Functions 4 September 8th 07 10:33 AM
Data value display attributes linked to table attributes MDT at Paragon Home Inspections, LLC Charts and Charting in Excel 0 November 15th 06 12:53 AM
How to count and group items in a list depending on size of list? Simon Lloyd[_859_] Excel Programming 3 August 13th 06 12:18 AM
How to count items in a list and group depending on size of list? Simon Lloyd[_712_] Excel Programming 5 April 28th 06 12:14 AM
Count rows with specific attributes in VBA Steve Newhouse Excel Worksheet Functions 3 February 25th 06 01:30 AM


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