IF > 0 THEN return corresponding Column & Row Header; for times the value occurred on each date

qadeerahmed

New Member
Joined
Nov 5, 2015
Messages
6
I' have a question somewhat similar to this post, but with some difference.

https://www.mrexcel.com/forum/excel...column-header-row-header-each-occurrence.html

[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD][/TD]
[TD]01-JAN-17[/TD]
[TD]02-JAN-17[/TD]
[TD]03-JAN-17[/TD]
[TD]04-JAN-17[/TD]
[TD]05-JAN-17[/TD]
[TD]06-JAN-17[/TD]
[TD]07-JAN-17[/TD]
[/TR]
[TR]
[TD]99XX1002[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]0[/TD]
[/TR]
[TR]
[TD="align: center"]99XX1003[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[/TR]
[TR]
[TD="align: center"]99XX1004[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]99RN1005[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]5[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 512"]
<tbody>[TR]
[TD]what I 'm looking is...

IF > 0 THEN return corresponding Column & Row Header; for times the value occurred on each date

e.g.
99xx1002 occurred 1 time on "02-Jan-17" and 3 times on "04-Jan-17 and 1 time on 05/06 jan....

I want to put this into tabular form like....[TABLE="class: outer_border, width: 500"]
<tbody>[TR]
[TD]99xx1002[/TD]
[TD]02-jan-17[/TD]
[/TR]
[TR]
[TD]99xx1002[/TD]
[TD]04-Jan-17[/TD]
[/TR]
[TR]
[TD]99xx1002[/TD]
[TD]04-Jan-17[/TD]
[/TR]
[TR]
[TD]99xx1002[/TD]
[TD]04-Jan-17[/TD]
[/TR]
[TR]
[TD]99xx1002[/TD]
[TD]05-Jan-17[/TD]
[/TR]
[TR]
[TD]99xx1002[/TD]
[TD]06-jan-17[/TD]
[/TR]
[TR]
[TD]99xx1003[/TD]
[TD]02-jan-17[/TD]
[/TR]
[TR]
[TD]99xx1003[/TD]
[TD]02-jan-17[/TD]
[/TR]
</tbody>[/TABLE]

Appreciate for your time and help:)

Thanks!
[/TD]
[/TR]
</tbody><colgroup><col span="8"></colgroup>[/TABLE]
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Book1
ABCDEFGH
101-Jan-1702-Jan-1703-Jan-1704-Jan-1705-Jan-1706-Jan-1707-Jan-17
299XX10020103110
399XX10030201300
499XX10040000001
599RN10052005000
Sheet1


This code will put a new table underneath:

Code:
Public Sub WBD2017052301()

Dim lastCol As Long
Dim lastRow As Long
Dim thisCol As Long
Dim thisRow As Long
Dim cellValue As Variant
Dim nextRow As Long

lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
lastRow = Cells(Rows.Count, 1).End(xlUp).Row

nextRow = lastRow + 2

For thisRow = 2 To lastRow
    For thisCol = 2 To lastCol
        cellValue = Cells(thisRow, thisCol).Value
        While cellValue > 0
            Cells(nextRow, 1) = Cells(thisRow, 1)
            Cells(nextRow, 1).NumberFormat = Cells(thisRow, 1).NumberFormat
            Cells(nextRow, 2) = Cells(1, thisCol)
            Cells(nextRow, 2).NumberFormat = Cells(1, thisCol).NumberFormat
            nextRow = nextRow + 1
            cellValue = cellValue - 1
        Wend
    Next thisCol
Next thisRow
    
End Sub

Like this:


Book1
AB
799XX100202-Jan-17
899XX100204-Jan-17
999XX100204-Jan-17
1099XX100204-Jan-17
1199XX100205-Jan-17
1299XX100206-Jan-17
1399XX100302-Jan-17
1499XX100302-Jan-17
1599XX100304-Jan-17
1699XX100305-Jan-17
1799XX100305-Jan-17
1899XX100305-Jan-17
1999XX100407-Jan-17
2099RN100501-Jan-17
2199RN100501-Jan-17
2299RN100504-Jan-17
2399RN100504-Jan-17
2499RN100504-Jan-17
2599RN100504-Jan-17
2699RN100504-Jan-17
Sheet1


WBD
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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