Posted on 2011-10-11
Medium Priority
Last Modified: 2012-05-12
Hi Guys

I am trying to allocate Names in the column by the amount of blank space and the number of time it should appear. Attached the example excel.Any help will be appreciated.

Question by:surah79
  • 3
  • 2
LVL 21

Expert Comment

by:Hendrik Wiese
ID: 36954158
For the Times you would use the following in C2:


Open in new window

For the Blank Spaces from the first X to the last X you would use the following:


Open in new window

I have attached the edited version for you reference.


Author Comment

ID: 36955257

Thanks for reply, I am sorry that I was not clear enough, I don't want to count, what I want is c opy
if X  4 times in the column with 1 blank row(depends on howmany blank row I would put the number in it) in between, or copy Y in the same column after A 2 times and
Name  Times blankSpace
X            2             1            so it X should be copied in the column 2 times and 1 row should be blank in between them so the output after the macro will be look as
LVL 21

Expert Comment

by:Hendrik Wiese
ID: 36955975
No sure what you mean..

Please edit the excel sheet with descriptions next to the shells explaining what you want them to do and then upload it again?

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 36959993
Hi attached the new excel
LVL 17

Accepted Solution

andrewssd3 earned 2000 total points
ID: 36968049
Try this - you need to select the range containing your instructions (without the headers), then click on the button - this will call this macro code:
Public Sub InsertNames(ByRef rngIn As Excel.Range)

    Dim rngOut As Excel.Range
    Dim c As Excel.Range
    Dim i As Long, j As Long, r As Long
    If rngIn.Columns.Count < 3 Then
        MsgBox "Please select a range containing at least 3 columns " & _
            "(Name, times, blank spaces)"
        Exit Sub
    End If
    ' this places the output below the input range, starting in the same column
    ' as the Name col - you could change this to be on a different sheet
    ' if you like
    Set rngOut = rngIn.Worksheet.UsedRange
    Set rngOut = rngOut.Offset(rngOut.Rows.Count, rngIn.Column - rngOut.Column).Resize(1, 1)

    For Each c In rngIn.Columns(1).Cells
        ' get the number of blank lines
        r = c.Offset(0, 2).Value
        ' loop as many times as requested
        For i = 1 To c.Offset(0, 1).Value
            rngOut.Cells(1, 1).Value = c.Value
            ' add the blank lines
            For j = 1 To r
                Set rngOut = rngOut.Offset(1, 0)
            Next j
            'move to the next cell
            Set rngOut = rngOut.Offset(1, 0)
        Next i
    Next c

End Sub

Open in new window


Author Closing Comment

ID: 36983368
Awesome thanks a lot

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question