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:
ABC
1Jan42
2Feb11
3Mar33
4Apr00

<tbody>
</tbody>

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
Mar
Mar
Mar
Feb
Jan
Jan

<tbody>
</tbody>

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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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

AB
1Jan1
2Feb0
3Mar7
4Apr3

<tbody>
</tbody>

And the list would look like
Apr
Apr
Apr
Mar
Mar
Mar

<tbody>
</tbody>

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,214,987
Messages
6,122,614
Members
449,091
Latest member
gaurav_7829

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