+ Reply to Thread
Results 1 to 3 of 3

copy rows based on a value in a cell

  1. #1
    Registered User
    Join Date
    12-27-2013
    Location
    Oklahoma City
    MS-Off Ver
    Excel 2003
    Posts
    49

    copy rows based on a value in a cell

    my data set references referrals to a provider, so it may say Referral Provider referred 5 patients during January. I'd like to reference the 5 to create 5 total row entries instead of a single row entry

    see row 4 in attached. Instead of a single row that shows Dr Cato referred 5 patients(Col F) I'd like 5 rows, each representing 1 referral from Dr Cato

    excel test.xlsx

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,719

    Re: copy rows based on a value in a cell

    Put zero in cell G1 and this formula in G2:

    =IF(F2="","",F2+G1)

    Copy this down to the bottom of your data (or beyond, to accommodate new data being added - I've copied to row 20 in the attached file). This formula just gives a cumulative count of the number of patients, so you can see that the last number (51) is the number of rows that you will need to have to record all patients individually.

    You can then use this formula in cell I2:

    =IF(ROWS($1:1)>MAX(G:G),"",MATCH(ROWS($1:1)-1,G:G)+1)

    and this will return the row where we want to get the data from. The following formula in J2:

    =IF($I2="","",INDEX(B:B,$I2))

    will get the data from column B on the row given by I2, and this formula can be copied across into K2:M2 to get data from the other three columns, C to E.

    Finally, you can copy the formulae in I2:M2 down as far as needed (given by the highest number in column G) - I've copied to row 55 in the example file, just to ensure that I pick up all the data.

    Hope this helps.

    Pete
    Attached Files Attached Files

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,002

    Re: copy rows based on a value in a cell

    In J2, use this array formula. Then copy across and downas far as needed.

    =IFERROR(INDEX(A$2:A$12,MATCH(0,--(COUNTIF(J$1:J1,A$2:A$12)=$F$2:$F$12),0)),"")

    Array Formulae are a little different from ordinary formulae in that they MUST be confirmed in the FIRST CELL ONLY by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. After that, the array can be dragged down as normal, to cover the desired range.

    You will know the array is active when you see curly brackets { } - or "curly braces" for those of you in the USA, or "flower brackets" for those of you in India - appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

+ 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] Insert rows based on the current cell value and, then, copy some cells into the new rows
    By Excel-RZ in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-03-2013, 05:19 PM
  2. [SOLVED] insert rows based on number in cell and copy the data down into the new rows
    By pziefle in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-05-2013, 11:19 AM
  3. Insert rows based on a value in a cell and copy the data down into the new rows
    By eyeman96 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-05-2013, 07:54 AM
  4. [SOLVED] Insert Multiple Rows Based Off Number in Cell and Copy Data From Above New Rows
    By tstell1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2012, 04:15 PM
  5. Need to copy rows to a different tab based on a cell value
    By grsnipe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2012, 07:55 AM
  6. copy rows based on a cell value
    By SMILE in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2011, 05:20 AM
  7. copy rows based on cell value
    By Przemek in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2005, 04:05 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