+ Reply to Thread
Results 1 to 22 of 22

Replacing Cells While Duplicating Range for N times

  1. #1
    Registered User
    Join Date
    09-18-2017
    Location
    Colombo 2
    MS-Off Ver
    2016
    Posts
    12

    Replacing Cells While Duplicating Range for N times

    Good day to all you excel gurus.
    I have come across this problem at work and need assistance.
    Please be kind enough to move the thread to any relevant sub if i'm posting it in the wrong place.

    I have an excel workbook with one sheet that has data as following
    Code Name Shelf Stock Cluster
    97 Item 1 14 XL
    98 Item 2 15 XL
    99 Item 3 5 XL
    100 Item 4 18 XL

    To explain you the scenario, this table contains the order quantities for a list of items for a collection of outlets called a cluster. In a cluster there might be 4 outlets. So this document is shared between 4 different sites.

    The list of outlets in the 'XL' cluster is as following: SCCC, SCUP, SCMG, SCCM.

    What i want to do is this:

    Code Name Shelf Stock Cluster
    97 Item 1 14 SCCC
    98 Item 2 15 SCCC
    99 Item 3 5 SCCC
    100 Item 4 18 SCCC
    97 Item 1 14 SCUP
    98 Item 2 15 SCUP
    99 Item 3 5 SCUP
    100 Item 4 18 SCUP
    97 Item 1 14 SCCM
    98 Item 2 15 SCCM
    99 Item 3 5 SCCM
    100 Item 4 18 SCCM
    97 Item 1 14 SCMG
    98 Item 2 15 SCMG
    99 Item 3 5 SCMG
    100 Item 4 18 SCMG

    I want to basically duplicate the range for n times (number of outlets in the cluster) but each time the range is duplicated, i want the cells in the "Cluster" column to be replaced with the outlet code.

    Currently i do this manually but it's very time consuming since there's 7 clusters and 70+ sites.
    Is there a way to automate this scenario?

    Thanks in advance!
    Nick~

  2. #2
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,935

    Re: Replacing Cells While Duplicating Range for N times

    Row\Col
    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    1
    Code Name Shelf Stock Cluster Cluster Number of Times
    4
    2
    97
    Item 1
    14
    XL SCCC
    3
    98
    Item 2
    15
    XL SCUP
    4
    99
    Item 3
    5
    XL SCMG
    5
    100
    Item 4
    18
    XL SCCM
    6
    7
    8
    Code Name Shelf Stock Cluster
    9
    97
    Item 1
    14
    SCCC
    10
    98
    Item 2
    15
    SCCC
    11
    99
    Item 3
    5
    SCCC
    12
    100
    Item 4
    18
    SCCC
    13
    97
    Item 1
    14
    SCUP
    14
    98
    Item 2
    15
    SCUP
    15
    99
    Item 3
    5
    SCUP
    16
    100
    Item 4
    18
    SCUP
    17
    97
    Item 1
    14
    SCMG
    18
    98
    Item 2
    15
    SCMG
    19
    99
    Item 3
    5
    SCMG
    20
    100
    Item 4
    18
    SCMG
    21
    97
    Item 1
    14
    SCCM
    22
    98
    Item 2
    15
    SCCM
    23
    99
    Item 3
    5
    SCCM
    24
    100
    Item 4
    18
    SCCM
    25
    26


    A9
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Copy across C column.

    D9
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Check the attached file.
    If I helped, Don't forget to add reputation (click on the little star ★ at bottom of this post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

  3. #3
    Registered User
    Join Date
    09-18-2017
    Location
    Colombo 2
    MS-Off Ver
    2016
    Posts
    12

    Re: Replacing Cells While Duplicating Range for N times

    Hi Shukla,

    I looked into the document you sent me and it works. I'm now working on making a document where i can paste the range in sheet 1, alter all the variables (Site list, number of times) in Sheet 2 and have the result show up in sheet 3. But i'm having a hard time understanding the function.

    If it's not too much to ask, could you please explain to me the different sections of the function and what they do?
    Eg: What does IFERROR do in this instance or Why use COUNTA? And i can't understand why you used the MOD function as well.

    Thanks so much!
    Last edited by Razzlesama; 09-18-2017 at 07:01 AM.

  4. #4
    Registered User
    Join Date
    09-18-2017
    Location
    Colombo 2
    MS-Off Ver
    2016
    Posts
    12

    Re: Replacing Cells While Duplicating Range for N times

    Hi Shukla,

    So i've been trying to modify your formula to work on an unlimited range across two sheets. The reason why i want to do is because i need to be able to just paste the range to a placeholder, insert the outlet codes and set the number of items and get the result in a different sheet. This workbook will be used by a bunch of people so i need it to work flawlessly.

    Here's what i did.
    Worksheets:
    1. Sheet 1: Data - Where i paste the range, site codes and number of items
    2. Sheet 2: Outlet-wise Shelf Stock - Where the end result is displayed


    Here's the modified formula:

    [Getting a firewall error if i posted this with the formula... How do i post it? ]

    I'm being returned the space set to return if any errors. But i don't understand what's wrong.

    I would much appreciate if you could have a look at this.
    Nick
    Last edited by Razzlesama; 09-19-2017 at 06:46 AM.

  5. #5
    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
    43,998

    Re: Replacing Cells While Duplicating Range for N times

    If your formula contains an < Succuri will block it. Try adding a space after the < Better still, attach a file. For what it's worth, I would have used a totally different (simpler) approach to this problem:

    A9, copied across and down:
    =IF($D9="","",INDEX(A$2:A$5,1+MOD((ROWS(A$9:A9)-1),$J$1)))

    D9, copied down:
    =IFERROR(INDEX($G$2:$G$5,MATCH(0,INDEX(--(COUNTIF($D$8:D8,$G$2:$G$5)=$J$1),0),0)),"")
    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

  6. #6
    Registered User
    Join Date
    09-18-2017
    Location
    Colombo 2
    MS-Off Ver
    2016
    Posts
    12

    Re: Replacing Cells While Duplicating Range for N times

    Hi Glenn, thank you for the new formula. Could you please explain to me how it works. Thanks!
    Last edited by Razzlesama; 09-19-2017 at 11:28 PM.

  7. #7
    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
    43,998

    Re: Replacing Cells While Duplicating Range for N times

    =IF($D9="","",INDEX(A$2:A$5,1+MOD((ROWS(A$9:A9)-1),$J$1)))

    Red: If d9 is blank, return blank
    Gold: This is simply a counter. As you drag it down, it returns 1,2,3,4,1,2,3,4,1,2,.....

    Basically in A9, rows(A9:a9) returns 1.
    1-1=0
    the remainder when you divide 0 by 4 is 0.
    Add 1 to that and you get 1.

    In A10, rows(A$9:a10) returns 2.
    2-1=1
    Divide by 4 and the remainder is... 1

    add 1 and you get... 2

    Green: return the corresponding value from here.


    =IFERROR(INDEX($G$2:$G$5,MATCH(0,INDEX(--(COUNTIF($D$8:D9,$G$2:$G$5)=$J$1),0),0)),"")

    Counts the No of times each of the values in G2 to G5 has appearred in the range D$8:D9. It returns TRUE until the count of the result = 4. Then it returns false, so the INDEX($G$2:$G$5 moves on to the next value and returns it up to 4 times...

  8. #8
    Registered User
    Join Date
    09-18-2017
    Location
    Colombo 2
    MS-Off Ver
    2016
    Posts
    12

    Re: Replacing Cells While Duplicating Range for N times

    Hey Glenn. I tried attaching a file to this reply but i don't get anything when i click on the file clip button?
    I could show you what i have done if i can attach the file.

  9. #9
    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
    43,998

    Re: Replacing Cells While Duplicating Range for N times

    Unfortunately the attachment icon doesn't work at the moment. So, to attach an Excel file you have to do the following: Just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.

  10. #10
    Registered User
    Join Date
    09-18-2017
    Location
    Colombo 2
    MS-Off Ver
    2016
    Posts
    12

    Re: Replacing Cells While Duplicating Range for N times

    Thanks.

    The formula works but with some errors. I attached the file here. I'm changing this so the people who'll be using this file could just copy the range and get the result without changing the formula.

  11. #11
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,935

    Re: Replacing Cells While Duplicating Range for N times

    Quote Originally Posted by Razzlesama View Post
    Thanks.

    The formula works but with some errors. I attached the file here. I'm changing this so the people who'll be using this file could just copy the range and get the result without changing the formula.
    I don't understand why you are not follow the steps provided in previous post. We always give you efficient and closer solution as per description provide from your end. Even in your last post you didn't described the errors you are getting. Also I would suggest you to please reduce the range as per need your file always get hang.....

  12. #12
    Registered User
    Join Date
    09-18-2017
    Location
    Colombo 2
    MS-Off Ver
    2016
    Posts
    12

    Re: Replacing Cells While Duplicating Range for N times

    Quote Originally Posted by shukla.ankur281190 View Post
    I don't understand why you are not follow the steps provided in previous post. We always give you efficient and closer solution as per description provide from your end. Even in your last post you didn't described the errors you are getting. Also I would suggest you to please reduce the range as per need your file always get hang.....
    I would have described the errors IF I KNEW WHAT THE ERRORS WERE! I'm a novice. I don't know what's happening or why it's not working. Hence why i'm here talking to you lovely people trying to figure out a solution. So i figured i should just attach the file without wasting time trying to explain something i don't even understand!

    And the reason why i'm trying to change things up is to try and understand the formula. I don't just want a solution, I WANT TO LEARN!

    Here's what i did:

    1. Made two new sheets. : Sheet number 1 contains the data to be duplicated while sheet 2 is for the result to be displayed.
    2. Copied Glenn's formula to the corresponding cell in the second sheet.
    3. Changed the ranges in the formulas to match the new locations. (IE: A2:A5 was changed to A2: A102010 - Reason is so i can just paste the values without ALTERING THE FORMULA EVERY TIME)

    Here's the deal. Duplicating data like this is a recurring exercise in my workplace. And more than twenty people will be using the file i build for that purpose. Some of them are even less knowledgeable about excel formulas than me. So I think it's better if they don't have to tamper with the formula every time they wanna use it. Because the number of items in this range to be copied will change every time they have to do it. And each cluster has different amounts of sites.

    There's 10 columns in the actual worksheet i'm working on. And some ranges may have more than 2500 rows. And if i was to use this file for a cluster like "M" which has 42 outlets, the result will have 2500*42=105,000 rows. The example i gave you only had 4 for ease of understanding. So it goes without saying i have to modify the formula to suit my needs!
    Last edited by Razzlesama; 09-20-2017 at 06:06 AM.

  13. #13
    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
    43,998

    Re: Replacing Cells While Duplicating Range for N times

    I am now totally confused. Your sheet is not clear!! Is it the case that sometimes, but not always that you want the cluster code copied down 4 times? If it is not ALWAYS four, then we need to add a column next to each cluster code to tell excel how many times cto copy that code down. You need to define some rules here....

    I no longer know what you want done. So, using realistic data, please explain again.

  14. #14
    Registered User
    Join Date
    09-18-2017
    Location
    Colombo 2
    MS-Off Ver
    2016
    Posts
    12

    Re: Replacing Cells While Duplicating Range for N times

    Hi Glenn. Sorry it was confusing.
    I'll explain to you what I want to do completely.

    1. My workplace is a retail chain with 70 outlets.
    2. These outlets are sorted to what we call "clusters" according to their size to make it easy to handle a range of about 28,000 items.
    3. XL cluster has 4 outlets, L has 10 outlets, M has 42 outlets, S has 2, XS has 5, XXS has 1 and there's one more cluster called 4K with 6 outlets.
    4. We design layouts for the racks in each cluster at the head office, one per each cluster and send it to the supply chain WEEKLY to calculate the order quantities for each item. These documents are called "Shelf Stock Per Cluster"
    5. We used to send them this information cluster-wise. Meaning, we send ONE file per cluster to the supply chain.
    6. But to make this more transparent, I decided to send this information PER OUTLET. Which means instead of 7 files, one per each cluster, I need to be sending 70 separate files, one per each outlet.
    7. For this, I must copy the information from each file, paste it to a new worksheet, once per outlet. But every time it gets pasted, the content of the "Cluster" column should get replaced with the outlet code. (IE: for XL cluster, the range should get duplicated 4 times. For L cluster, the range should get duplicated 10 times)

    -----
    That's the scenario.
    Here's the specifics of the files.

    1. The "Shelf Stock" file will ALWAYS have the following 10 columns.
    Fixel_ID Product_ID Name HOR_FACING VER_FACING DEP_FAC SHELF STOCK RANK OUTLET DISPLAY CATEGORY

    2. The biggest of the 7 "Shelf Stock" files, which is the file for the "M" cluster, has around 2500 rows.
    3. I need to be able to
    • copy paste the content from ONE "Shelf Stock" file at a time within the "A:J" cell range, to the "Data" worksheet (Maximum of 2500 rows down)
    • set the number of outlets in the "O1" cell,
    • type in the outlet codes per cluster into column “L” (Maximum of 60 rows down)
    • and get the result in the NEXT sheet which I named "Result"
    4. Other sheets are only there for my understanding. I will be deleting them once the formula works.
    Again, I thank you for trying to help me here.

  15. #15
    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
    43,998

    Re: Replacing Cells While Duplicating Range for N times

    I think that I follow you.

    Sheet1, A2, copied down:
    =IF($K2="","",INDEX(Data!A$2:A$36,1+MOD((ROWS(A$2:A2)-1),Data!$O$1)))
    This will copy the entire set of stock lines (35) down 4 times (once for each outlet code)

    Sheet1, K2, copied down:
    =IFERROR(INDEX(Data!L$2:L$5,MATCH(0,INDEX(--(COUNTIF($K$1:K1,Data!L$2:L$5)=Data!$O$1),0),0)),"")
    This will copy each outlet code 35 times before moving on to the next one.

    Data, O1,
    35
    (there being 35 lines of product each of which has to be replicated 4 times, once for each outlet code).

    If this not correct, please explain - using the sort of terminology that I have used - what you need. Keep it short and absolutely clear.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    09-18-2017
    Location
    Colombo 2
    MS-Off Ver
    2016
    Posts
    12

    Re: Replacing Cells While Duplicating Range for N times

    It works perfectly!

    Thank you!

    I just have to delete the records with "0" at the end for the outlet code. Which is fine by me.

    I made some changes as you can see in the working.
    1. In Sheet 1, cell O1, I gave a formula to count the number of items as following.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    2. In sheet 1, cell O2, I gave a formula to count the number of outlets.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    3. Then on sheet 2, cell K2, I modified the formula as such :
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    This is so the range of the formula doesn't have to be altered manually.

    Have i done this correctly? I get blank output in the K2 cell in Sheet 02 after making this change.
    Attached Files Attached Files

  17. #17
    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
    43,998

    Re: Replacing Cells While Duplicating Range for N times

    I think I'll become an alcoholic...

    What on earth do you think this bit is doing???

    INDIRECT(CONCATENATE("D",Data!$O$2)

  18. #18
    Registered User
    Join Date
    09-18-2017
    Location
    Colombo 2
    MS-Off Ver
    2016
    Posts
    12

    Re: Replacing Cells While Duplicating Range for N times

    Oh man.

    I thought instead of having
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    I could give the cell range with another cell.

    Like, instead of typing C2:C9, I could give C2:Cn where n is a value I define in a different cell.

    Is there any way to do that? I searched and found
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    would return D and the value inside the cell 'O2' in the sheet called data. IE: if 'O2' has the number '10' in it, the result would be D10?

  19. #19
    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
    43,998

    Re: Replacing Cells While Duplicating Range for N times

    At the risk of getting even stranger modifications... but trying to remove the possibility of further human error, I have created 3 named ranges (CTRL-F3 to view them). They will adjust automatically (up to 10000 rows) to the size of your dataset.

    Formulae now refer to the named ranges.

    Glenn sits back... waits for a response and reaches for the corkscrew....
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    09-18-2017
    Location
    Colombo 2
    MS-Off Ver
    2016
    Posts
    12

    Re: Replacing Cells While Duplicating Range for N times

    Haha you even named it final.. Fair enough.

    This works as i wanted to.
    Could i ask for an explanation like before?

    Thanks so much!

  21. #21
    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
    43,998

    Re: Replacing Cells While Duplicating Range for N times

    I wondered if you would spot the file name...

    The formulae in the sheet have not changed. They work as previously. However, instead of manually adjusting ranges I used 3 named ranges to automate.One was this (Outlet_Rng):
    =Data!$L$2:INDEX(Data!$L$2:$L$10000,COUNTA(Data!$L$2:$L$10000))


    which establishes the range of the cells containing your outlet codes.
    Red: Begin in this cell
    Green: look down this range as far as
    Blue: the last non-blank cell

    Items_Rng was similar. he last one was Items_Cnt, a count of the number of stock items:

    =COUNTA(Data!$A$2:$A$10000)

    That hardly needs an explanation. That's it. Use the names of the named ranges, instead of cell references in your formulae and... job done.





    If that takes care of your original question, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.

    It'd also be appreciated if you were to click the Add Reputation button at the foot of any of the posts of all members who helped you reach a solution.

  22. #22
    Registered User
    Join Date
    09-18-2017
    Location
    Colombo 2
    MS-Off Ver
    2016
    Posts
    12

    Re: Replacing Cells While Duplicating Range for N times

    Thanks Glenn. Marked the thread as solved.

+ 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] Counting how many times a range of key words come up in a range of cells
    By Piepongwong in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 09-04-2014, 02:38 PM
  2. [SOLVED] Need to automate the copying of range of cells into same row 365 times
    By Hirad001 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-07-2014, 01:36 PM
  3. [SOLVED] Replacing a Range of Cells in Excel
    By joker25 in forum Excel General
    Replies: 7
    Last Post: 12-16-2013, 09:40 AM
  4. [SOLVED] Need formula to sum range of cells consecutively across a row not duplicating used cells
    By angie18a in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-28-2013, 03:46 PM
  5. copying 2 cells multiple times to a range
    By NewToVBA_23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2013, 06:09 PM
  6. Duplicating X number of rows Y times automatically
    By rwwilcox in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-15-2012, 07:53 AM
  7. Replacing range in formula for many cells
    By jimstrongy in forum Excel General
    Replies: 3
    Last Post: 12-21-2011, 03:31 PM

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