Suggestions wanted on how to display table of info

meileetan

Board Regular
Joined
Aug 18, 2005
Messages
86
Hello,
I have a sheet of raw data like this:
Column A Column B Column C
Item Condition X Condition Y
A Y Y
A N N
B Y Y
B N Y
B Y Y

I would like a table that counts the no. of "Y" for each of the items A and B. So something that looks like this:
Item Condition X Condition Y
A 1 1
B 2 3

Can a pivot table do this?

Thank you.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
meileetan,


Sample raw data before the macro:


Excel Workbook
ABCDEFG
1ItemCondition XCondition Y
2AYY
3ANN
4BYY
5BNY
6BYY
7
Sheet1





After the macro:


Excel Workbook
ABCDEFG
1ItemCondition XCondition YItemCondition XCondition Y
2AYYA11
3ANNB23
4BYY
5BNY
6BYY
7
Sheet1





If you were to add more data to columns A, B and C, and run the macro again, columns E, F, and G will be cleared, and then columns E, F, and G will be re-created.




Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub CountItem()
'  hiker95, 07/18/2011
' http://www.mrexcel.com/forum/showthread.php?t=564946
Dim LR As Long, LR2 As Long
If Range("A1") <> "Item" Then
  MsgBox "Cell A1 does not contain 'Item' - macro terminated!"
  Exit Sub
End If
Application.ScreenUpdating = False
Columns("E:G").ClearContents
Columns("A:A").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Columns("E"), Unique:=True
Range("F1").Resize(, 2).Value = Range("B1").Resize(, 2).Value
LR = Cells(Rows.Count, 1).End(xlUp).Row
LR2 = Cells(Rows.Count, 5).End(xlUp).Row
With Range("F2:F" & LR2)
  .FormulaR1C1 = "=SUMPRODUCT(--(R2C1:R" & LR & "C1=RC5),--(R2C2:R" & LR & "C2=""Y""))"
  .Value = .Value
End With
With Range("G2:G" & LR2)
  .FormulaR1C1 = "=SUMPRODUCT(--(R2C1:R" & LR & "C1=RC5),--(R2C3:R" & LR & "C3=""Y""))"
  .Value = .Value
End With
Columns("E:G").AutoFit
Application.ScreenUpdating = True
End Sub


Then run the CountItem macro.
 
Upvote 0
Try the Pivot Table Wizard.

Select your data.
Then choose Data, Pivot Table, to invoke the wizard.
Then follow the steps it takes you through.
 
Upvote 0
Hi Gerald,
The wizard doesn't give me the layout I want. It is giving the following:
Item Condition X=Y Condition X=N
Condition Y=Y Condition Y=N Condition Y=Y Condition Y=N
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,671
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top