Populate data according to number

YasserKhalil

Well-known Member
Joined
Jun 24, 2010
Messages
852
Hello
I have the range("C1:C30") This is the range where I want to populate my data

The numbers which I will distribute the data according is in C33:C37
Say for example (5 - 6 - 4 - 10 - 3)

The total of these number are 28 so the first two cells C1 and C2 will be empty
From C3:C7 should be filled with "A"
From C8:C13 should be filled with "B"
From C14:C17 should be filled with "C"
From C18:C27 should be filled with "D"
From C28:C30 should be filled with "E"

Note that the numbers are variables not constants

I hope that is clear
 

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.
Please do it ... Even reply
Please be patient! Two 'bumps' in less than two hours is way too much and you will soon turn people off helping you if appear impatient.
Remember it is weekend and not so many members are on the forum (giving their time for free).

You could try this macro.
Rich (BB code):
Sub Populate_Numbers()
  Dim Data, Results(1 To 30, 1 To 1)
  Dim i As Long, j As Long, k As Long, p As Long
  
  Const sLetters As String = "ABCDE"
  
  p = Len(sLetters)
  Data = Range("C33:C37").Value
  i = 30
  For j = 5 To 1 Step -1
    For k = 1 To Data(j, 1)
      Results(i, 1) = Mid(sLetters, p, 1)
      i = i - 1
    Next k
    p = p - 1
  Next j
  Range("C1:C30") = Results
End Sub
 
Upvote 0
Mr. Peter
I'm so sorry for being impatient . I just need this quickly
Perfect solution.
Thank you very much...

Just one thing I want to extend the range to be C33:G37 and to apply the previous fantastic code to the columns ("C:G")
 
Upvote 0
I'm patient .. waited for more than 6 hours
Just one thing I want to extend the range to be C33:G37 and to apply the previous fantastic code to the columns ("C:G")
 
Upvote 0
I'm patient Mr. Peter Did you notice that?
As a matter of fact I didn't, as that post was made at 3:07 AM my time! Even though it does often happen expecting an answer within 4 hours is very demanding.

I'm patient .. waited for more than 6 hours
That 7 hours was from 11:26 PM to 6:20 AM my time. Surprising as it may seem, I tend to sleep during that period. :)

Waiting for your share Mr. Peter
Now that is a more respectable period to wait before 'bumping'.

See if this does what you want.

Rich (BB code):
Sub Populate_Numbers()
  Dim Data, Results(1 To 30, 1 To 5)
  Dim i As Long, j As Long, k As Long, p As Long, y As Long
  
  Const sLetters As String = "ABCDE"
  
  Data = Range("C33:G37").Value
  For y = 1 To 5
    p = Len(sLetters)
    i = 30
    For j = 5 To 1 Step -1
      For k = 1 To Data(j, y)
        Results(i, y) = Mid(sLetters, p, 1)
        i = i - 1
      Next k
      p = p - 1
    Next j
  Next y
  Range("C1:G30") = Results
End Sub
 
Upvote 0
Mr. Peter
I don't know how to say thanks to you as thank you is a little word for what you offered me
And I'm sorry for being impatient .. I will try to train myself to be more patient
Thanks again Mr. Great Peter
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,170
Members
448,870
Latest member
max_pedreira

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