+ Reply to Thread
Results 1 to 6 of 6

Inserting Rows Based on a Cell Value and Pasting Text from Another

Hybrid View

  1. #1
    Registered User
    Join Date
    05-15-2020
    Location
    North America
    MS-Off Ver
    Office365 (v2209)
    Posts
    35

    Inserting Rows Based on a Cell Value and Pasting Text from Another

    Hello,

    New to this forum. I work in healthcare.

    I have an Excel issue I need to resolve. I have two columns of data. In Col A I have a list of 600 rows of unique zip codes. In Col B, I have the number of patients that live in that zip code. Example:

    Zip Code Number of Pts
    37362 25
    37363 110
    37365 14
    37366 9
    37367 62
    37369 8
    37370 14
    37373 23
    37374 13
    37375 7
    33928 1

    etc...

    If you sum the total of Col B, there are about 15000 patients with many living in the same zip code. I need to get all the zip codes in a single column, even if they are duplicates. I need to plot this out on a map to visualize the physical distribution of these patients.

    Is there any way to do this in an efficient manner? I'm thinking of a macro but I'm not sure that's going to work.

    For Col B values > 1, I'd need to add row(s) below based on the value of that cell minus one. So for Zip Code 37362, there are 25 patients. I need to insert 24 rows below and then copy the zip code from Col A in each cell below. I can do this manually but it would be very time consuming.

    Any suggestions?

  2. #2
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: Inserting Rows Based on a Cell Value and Pasting Text from Another

    Hi, you could try this macro:
    Sub Insert_Rows()
        Dim i&, j&, lro&, numrows&
        lro = Cells(Rows.Count, "A").End(xlUp).Row
        i = 1
        Do Until i = lro
        numrows = Cells(i, 2).Value-1
            For j = 1 To numrows 
                Cells(i + 1, 2).EntireRow.Insert xlShiftDown
                Cells(i + 1, 1) = Cells(i, 1)
            Next j
            lro = lro + numrows 
            i = i + numrows 
            i = i + 1
        Loop
    End Sub
    Cheers
    Erwin
    Last edited by Eastw00d; 05-16-2020 at 07:27 AM.
    I started learning VBA because I was lazy ...
    Still developing.... being more lazy...

  3. #3
    Registered User
    Join Date
    05-15-2020
    Location
    North America
    MS-Off Ver
    Office365 (v2209)
    Posts
    35

    Re: Inserting Rows Based on a Cell Value and Pasting Text from Another

    Thanks Erwin,

    I created a blank macro then pasted your code into it. When I run it, I get am error:

    Run-time error '13':
    Type mismatch

    My VB skills are practically non existent.

  4. #4
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: Inserting Rows Based on a Cell Value and Pasting Text from Another

    Perhaps if you copy your data into this workbook:
    Another possibility is that you upload yours, without confidential data, and I will put the code in there.

    Cheers
    Erwin
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-15-2020
    Location
    North America
    MS-Off Ver
    Office365 (v2209)
    Posts
    35

    Re: Inserting Rows Based on a Cell Value and Pasting Text from Another

    Erwin,

    That worked like a charm!!! Thank you so much. I really appreciate that. I have a few of these spreadsheets to do and this made my life a lot easier.

    SB

  6. #6
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: Inserting Rows Based on a Cell Value and Pasting Text from Another

    That's why we're doing this
    Have a blessed day!
    Cheers
    Erwin

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA Help with Pasting and Inserting Cells Based
    By JSH2017 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-10-2018, 07:31 PM
  2. Inserting rows based on cell
    By hei.so in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2018, 05:40 PM
  3. inserting rows and text based on criteria
    By inggar1618 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-23-2014, 04:39 PM
  4. Replies: 0
    Last Post: 05-20-2014, 11:58 AM
  5. Inserting Rows Based on Cell Value.
    By feather-chaser in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2014, 05:39 AM
  6. Inserting, Cutting, and Pasting Rows Based on What's in a Cell
    By 4EverLearning in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-05-2010, 04:42 PM
  7. Inserting rows based on cell value
    By iwontbelost in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-17-2009, 07:45 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1