Count values and list them

dado6612

Well-known Member
Joined
Dec 4, 2009
Messages
591
Hi all,
Small 2 part problem
Need to "extract" values which add up to 6 from column B to column C, starting from bottom, which would look like:
[TABLE="class: grid, width: 50"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Jan[/TD]
[TD]4[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Feb[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Mar[/TD]
[TD]3[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Apr[/TD]
[TD]0[/TD]
[TD]0[/TD]
[/TR]
</tbody>[/TABLE]

Note: value in column A might be higher than 6, not less than 0
After that, in cell A6, list values from column A, starting from bottom, as many times the value is in column C
[TABLE="class: grid, width: 50"]
<tbody>[TR]
[TD="align: center"]Mar[/TD]
[/TR]
[TR]
[TD="align: center"]Mar[/TD]
[/TR]
[TR]
[TD="align: center"]Mar[/TD]
[/TR]
[TR]
[TD="align: center"]Feb[/TD]
[/TR]
[TR]
[TD="align: center"]Jan[/TD]
[/TR]
[TR]
[TD="align: center"]Jan[/TD]
[/TR]
</tbody>[/TABLE]

Column C is not really needed, can only serve as a help for the final list.

Hope it's simple enough and understood.
Thank you :)
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Beg your pardon, but could not really understand what and where "extract"...
 
Upvote 0
Do not know how else to explain, basically wish that first 6 values, starting from bottom, are listed in rows under the table.

As in given example, Apr has value of 0, so it's skipped, Mar is 3, so it will be listed first, 3 times; with 3 spaces left
Feb once and finally completing the list with Jan twice.

Maybe one more example can help

[TABLE="class: grid, width: 50"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]Jan[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]Feb[/TD]
[TD="align: center"]0[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]Mar[/TD]
[TD="align: center"]7[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]Apr[/TD]
[TD="align: center"]3[/TD]
[/TR]
</tbody>[/TABLE]

And the list would look like
[TABLE="class: grid, width: 50"]
<tbody>[TR]
[TD="align: center"]Apr[/TD]
[/TR]
[TR]
[TD="align: center"]Apr[/TD]
[/TR]
[TR]
[TD="align: center"]Apr[/TD]
[/TR]
[TR]
[TD="align: center"]Mar[/TD]
[/TR]
[TR]
[TD="align: center"]Mar[/TD]
[/TR]
[TR]
[TD="align: center"]Mar[/TD]
[/TR]
</tbody>[/TABLE]

Hope it helps
 
Upvote 0
Does this macro do what you want...
Code:
[table="width: 500"]
[tr]
	[td]Sub SixValuesOnly()
  Dim R As Long, X As Long, Cnt As Long, LastRow As Long, Ans(1 To 6, 1 To 1) As String
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  For R = LastRow To 1 Step -1
    If Cells(R, "B").Value > 0 Then
      For X = 1 To Cells(R, "B").Value
        Cnt = Cnt + 1
        If Cnt = 7 Then GoTo Continue
        Ans(Cnt, 1) = Cells(R, "A").Value
      Next
    End If
  Next
Continue:
  Cells(LastRow + 3, "A").Resize(6) = Ans
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Always the same. I can keep it simple to make your work easier.
The table A1:B17, where in column A are names and in B are numbers.
The list can go under it, A18.
 
Upvote 0

Forum statistics

Threads
1,224,826
Messages
6,181,192
Members
453,021
Latest member
pingpong7117

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