+ Reply to Thread
Results 1 to 18 of 18

Loop Code Help

  1. #1
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Loop Code Help

    I want a loop macro that looks at data in column H on sheet2 and if in that column there contains the word Data then I want to copy the entire row where the word data is found and then go to Sheet1 and paste that row in the corresponding row. It needs to be pasted in the row where there is a match for contents in column F. So for example, if the word Data is found in Sheet2 column H row 7 then I want to copy that row and then look at row7 in sheet 2 column F and try and find a match for it in Sheet1 column F and if a match is found paste the row I copied into whatever row the match was found.

  2. #2
    Forum Contributor
    Join Date
    07-04-2012
    Location
    Al Khor, Qatar
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Loop Code Help

    Can you please attach a sample workbook. thank you

  3. #3
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Loop Code Help

    sample.xlsm

    Here it is attached.

  4. #4
    Forum Contributor
    Join Date
    07-04-2012
    Location
    Al Khor, Qatar
    MS-Off Ver
    Excel 2013
    Posts
    101

    Re: Loop Code Help

    Please try this code.. try this 1.xlsm

  5. #5
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Loop Code Help

    Not exactly what I want. Your code assumes the cell contents to be pasted into are on the same row as where you find Data. In the sample I sent the rows that need to be updated are rows 41 and 42 but these numbers can change so I need a code that looks for the values in column F, then matches that column to sheet 1 column F, then paste the new data.

  6. #6
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Loop Code Help

    Please Login or Register  to view this content.
    This is what I have at the minute. It runs fine but doesn't do what I need! Any ideas?

  7. #7
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Loop Code Help

    Give this try.

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  8. #8
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Loop Code Help

    It gives me an error AutoFIlter method of Range class failed and highlights the line " .AutoFilter Field:=8, Criteria1:="Data"".

  9. #9
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520
    Are running the code from the attached wb? If so be sure the macro is in a standard module and NOT a worksheet module.

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Loop Code Help

    See attached wb

    sample_v2.xlsm

  11. #11
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Loop Code Help

    I found the issue. I've added a few blank rows at the top of sheet2 and then it gives me the error. Any way of resolving this regardless of how many blank rows at the top?

  12. #12
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Loop Code Help

    You change this line

    Please Login or Register  to view this content.

  13. #13
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Loop Code Help

    Many thanks. Works perfectly. Is there anyway to code it so that it runs no matter how far down the data starts?

  14. #14
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Loop Code Help

    I've just noticed that if sheet2 data begins on row4 andso does sheet1, and I change it to A3, it doesn't work.....strange?

  15. #15
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Loop Code Help

    Not to be rude but why would you have your data starting below row 2?

  16. #16
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Loop Code Help

    As I may be inserting various buttons above the data which will run different macros.

  17. #17
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Re: Loop Code Help

    I will be adding buttons that will run various macros at the top of the sheet so my data wont be able to start in row 2 for spacing reasons.

  18. #18
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Loop Code Help

    Not telling you what you should do, but if it was me I would look into creating a custom ribbon.

    You can look at Ron's Website

    http://www.rondebruin.nl/ribbon.htm

    and this link is on his website to download the editor.
    http://openxmldeveloper.org/archive/...mUIeditor.aspx

+ 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