VBA for pivot like table (but not pivot)

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

With some VBA, I collect the information in columns A and B and then create column D for the unique items and the names of the sheets they were found in from E1 across.

What I would now like to do is fill in the yellow area with something simple like an "x" to denote if it exists in that sheet and blank if not. Can someone help me with some code to do this please?


<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 8pt; FONT-FAMILY: Arial,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><COLGROUP><COL style="FONT-WEIGHT: bold; WIDTH: 30px"><COL style="WIDTH: 87px"><COL style="WIDTH: 65px"><COL style="WIDTH: 56px"><COL style="WIDTH: 92px"><COL style="WIDTH: 87px"><COL style="WIDTH: 56px"><COL style="WIDTH: 56px"><COL style="WIDTH: 56px"></COLGROUP><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD> </TD><TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD><TD>F</TD><TD>G</TD><TD>H</TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD style="FONT-WEIGHT: bold">Item</TD><TD style="FONT-WEIGHT: bold">Sheet Name</TD><TD style="FONT-WEIGHT: bold"> </TD><TD style="FONT-WEIGHT: bold">Unique Item</TD><TD style="FONT-WEIGHT: bold; TEXT-ALIGN: right">1</TD><TD style="FONT-WEIGHT: bold; TEXT-ALIGN: right">2</TD><TD style="FONT-WEIGHT: bold; TEXT-ALIGN: right">3</TD><TD style="FONT-WEIGHT: bold; TEXT-ALIGN: right">4</TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD>A</TD><TD style="TEXT-ALIGN: right">1</TD><TD> </TD><TD>A</TD><TD style="BACKGROUND-COLOR: #ffff00">x</TD><TD style="BACKGROUND-COLOR: #ffff00">x</TD><TD style="BACKGROUND-COLOR: #ffff00">x</TD><TD style="BACKGROUND-COLOR: #ffff00">x</TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD>A</TD><TD style="TEXT-ALIGN: right">2</TD><TD> </TD><TD>B</TD><TD style="BACKGROUND-COLOR: #ffff00">x</TD><TD style="BACKGROUND-COLOR: #ffff00">x</TD><TD style="BACKGROUND-COLOR: #ffff00">x</TD><TD style="BACKGROUND-COLOR: #ffff00">x</TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD>A</TD><TD style="TEXT-ALIGN: right">3</TD><TD> </TD><TD>C</TD><TD style="BACKGROUND-COLOR: #ffff00">x</TD><TD style="BACKGROUND-COLOR: #ffff00">x</TD><TD style="BACKGROUND-COLOR: #ffff00">x</TD><TD style="BACKGROUND-COLOR: #ffff00"> </TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">5</TD><TD>A</TD><TD style="TEXT-ALIGN: right">4</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">6</TD><TD>B</TD><TD style="TEXT-ALIGN: right">1</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">7</TD><TD>B</TD><TD style="TEXT-ALIGN: right">2</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">8</TD><TD>B</TD><TD style="TEXT-ALIGN: right">3</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">9</TD><TD>B</TD><TD style="TEXT-ALIGN: right">4</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">10</TD><TD>C</TD><TD style="TEXT-ALIGN: right">1</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">11</TD><TD>C</TD><TD style="TEXT-ALIGN: right">2</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 19px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">12</TD><TD>C</TD><TD style="TEXT-ALIGN: right">3</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR></TBODY></TABLE>

I'm thinking I need to use nested loops to loop through column A and across row 1 (from E1 onwards) and use some sort of:

IF item = unique item AND sheet name = E1 then x

But I'm getting lost coding this.

Thank you in advance,
Jack
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Although you say ("but not pivot") - I created a PT based on your Columns A & B; Making some other setting-adjustments - the final results (PT) in D:H look pretty much like what you want...
Excel Workbook
ABCDEFGH
1ItemSheet NameUnique Item
2A11234
3A2Axxxx
4A3Bxxxx
5A4Cxxx
6B1
7B2
8B3
9B4
10C1
11C2
12C3
Sheet1
Excel 2007
 
Upvote 0
Can't you just add formulas to the table to calculate if the count is greater than 0?
 
Upvote 0
Jim - thanks for the suggestion, but very much so need to avoid pivot tables in this requirement

Rory - can you give me an example of the formula please? I should be able to take it from there
 
Upvote 0
=IF(SUMPRODUCT(--($A$2:$A$12=$D2),--($B$2:$B$12=E$1))>0,"X","")
should work.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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