+ Reply to Thread
Results 1 to 19 of 19

Tried to Build a Macro, but couldn't make it repeat for multiple rows.

  1. #1
    Registered User
    Join Date
    03-04-2013
    Location
    Tennessee, USA
    MS-Off Ver
    2010
    Posts
    13

    Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    I have built several spreadsheets over the years, but this is my first time to try my hand at macros. My current workbook has 17 sheets almost all providing data of some kind to another sheet. Sheet 1 calculates the variable price of parts based on size & number of operations. The inputted data is moved to 6 different sheet and back to sheet 1 with 6 sets of pricing.
    Sheet 17 is a list of parts with the different sizes and operations listed. There are 1200 different parts. Currently I copy 4 cells of data form one row on sheet 17 and paste it into sheet 1; then I copy the values generated on sheet 1 and paste special the data on the row where I originally copied the data from on sheet 17.
    I am trying to automate this. Sometimes I fail in pasting special and just paste; that just results in incorrect pricing. I created a macro recording, but it only does the one row. I need some guidance.
    Thanks in advance!

    I have attached a sample file
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    You need to give more information on whay are trying to do. Are you trying to consolidate all data in to a master sheet, or similar?

  3. #3
    Registered User
    Join Date
    03-04-2013
    Location
    Tennessee, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    I am trying to take each row of data from the last sheet (sheet17) and plug it into the master sheet, copy the values generated form the master sheet and paste it beside the row of data(sheet 17).
    Does that make sense?

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    So, you are recycling from sheet 17 to master and then from master to sheet 17 again.

  5. #5
    Registered User
    Join Date
    03-04-2013
    Location
    Tennessee, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    more or less.
    Sheet 17 data 10.00 , 1 , 3 , 2 (1000 rows) copy
    Paste into Master. It generates pricing $15.00, $13.00, $9,50, $7.00, $5.75 copy pricing
    Paste into sheet 17 beside the original data so it would look like 10.00 , 1 , 3 , 2, $15.00, $13.00, $9,50, $7.00, $5.75

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    Okay!
    Which columns and rows from sheet 17 are going in to master as you have hidden columns? I can see that columns I-M of master are copied in to sheet 17 in column J-N.

  7. #7
    Registered User
    Join Date
    03-04-2013
    Location
    Tennessee, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    The hidden rows are junk for other purposes. Copy each row from sheet17 columns F,G, H, I to Master $B$5, $C$5, $D$5, $E$5.
    Answer Copy values $I$7, $J$7, $K$7, $L$7, $M$7 back to sheet17 J-M on the row the data was originally copied from.

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    homike,
    I am sure I am missing something. I do not think you need a code to do this task, linking the sheets with a formula would have been suffice. See if you want me to add more to the code, probably clearing the cells before copying.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    03-04-2013
    Location
    Tennessee, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    That isn't what I was looking for. I have updated the sheet. Look at Sheet 17 now. I think it will make a little more sense.
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    "Copy each row from sheet17 columns F,G, H, I to Master $B$5, $C$5, $D$5, $E$5.
    Answer Copy values $I$7, $J$7, $K$7, $L$7, $M$7 back to sheet17 J-M on the row the data was originally copied from. "

    Which of the two or both, is not working for you? Which one is correct and which one is not. Do you want to copy fom row 2 all the way down? I though the data for master sheet came from sheet 17 which is at the moment is blank.

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    The data you have in master sheet row 7 is copied in to sheet 17 of row 12. Why is this not copied in to row 1 and where did you get the other data from row 2 to row 11 from?

  12. #12
    Registered User
    Join Date
    03-04-2013
    Location
    Tennessee, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    each row on sheet 17 supplies the data for the master sheet. Copy each row of data from sheet 17 (1 row at a time)and then paste it into B5, C5, D5, E5 on the Master sheet. That generates answers on the Master Sheet in cells I7, J7, K7, L7, M7. Those cells are then copied and values pasted to Sheet 17 on the row along side from where the original data was copied from.

    That is why I was thinking macro. It is a fairly simple (copy and paste) then (copy and paste special); but I couldn't figure out how to make a macro run on each line of sheet 17.

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    Why a single cell at a time? On what bases is then this single row to be copied decided? You can loop through each row at a time, but there is not point if it is a single row. As I said before, I am not getting what are you trying to achieve. My guess was you want to fill in column I-M of master sheet with formula-which is linked with the data copied from sheet 17.

  14. #14
    Registered User
    Join Date
    03-04-2013
    Location
    Tennessee, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    Ok. Sheet 17 is a list of part numbers that has 4 variables. Length, Baffles, Holes, & Angles. If any of the 4 change, it will change the final price. I have to provide tiered pricing to my customer; five price points. 25 pcs, 50 pcs, 100 pcs, 150 pcs, 200 pcs. I don't copy a single cell at a time, but 4 cells and paste them into a set location to generate the pricing. I then copy the pricing back to the part number row. I have to provide this list (sheet 17) to my customer. I am going to change the appearance of the master & sheet 17. See if that makes more sense now.

    I see it, but I'm not good at explaining it. Sorry for the confusion. I have to leave for the day. I will be back in the morning.

    Thanks again for all your help.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    03-04-2013
    Location
    Tennessee, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    Good Morning One and All! I am hoping to resolve this today if it is even possible. I don't know what the limits of Excel are. I need to copy 4 cells of data from one sheet and pate it into another sheet. Once pasted, it will generate 5 answers. The values of those 5 answers/cells need to be copied and pasted back to the original sheet along side the 4 cells of data that was first copied. I made a macro that would do that very thing. The problem is to have it move down to the next row of data, copy those 4 cells and paste it over the first 4 cells pasted thus generating 5 more answers; coping them and pasting the values of them along side that next set of data copied from the original sheet.

    To me, it would need to be some sort of loop, but I have no clue as how to set it up. That is why I have come here hoping that there is an excel guru that could help me.

  16. #16
    Registered User
    Join Date
    03-04-2013
    Location
    Tennessee, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    Ok. I have a new sheet that should make this easier to follow.

    1. Copy one row from Data sheet.
    2. Paste into Master sheet. (it will generate a solution)
    3. Copy the solution from Master sheet & paste the values on the Answer sheet.
    4. Repeat for every row of data in Data sheet.

    This is basically what I am doing in the other workbook. My question is one is this possible with a macro? Second, if so, how?

    Thanks in advance!! Maybe this can be done?
    Attached Files Attached Files
    Last edited by homike2; 03-05-2013 at 11:45 AM.

  17. #17
    Registered User
    Join Date
    03-04-2013
    Location
    Tennessee, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    Is there a macro that will let you copy sequential rows of data?

  18. #18
    Registered User
    Join Date
    03-04-2013
    Location
    Tennessee, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    I'm guessing this is an unsolvable problem?

  19. #19
    Registered User
    Join Date
    03-04-2013
    Location
    Tennessee, USA
    MS-Off Ver
    2010
    Posts
    13

    Re: Tried to Build a Macro, but couldn't make it repeat for multiple rows.

    Sub test()


    Dim rCell As Range
    Dim LastRow As Integer


    Sheets("Data").Activate

    For Each rCell In Range("a2", Range("a2").End(xlDown))

    Range(Cells(rCell.Row, 1), Cells(rCell.Row, 5)).Select

    Selection.Copy

    Sheets("Master").Select

    Range("A5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    Application.CutCopyMode = False
    Calculate

    Range("A15:F15").Select

    Selection.Copy

    Sheets("Answer").Select

    LastRow = Range("A65536").End(xlUp).Row

    Cells(LastRow + 1, 1).Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    Sheets("Data").Activate

    Next rCell


    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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