+ Reply to Thread
Results 1 to 12 of 12

Macro that replaces repeating the same steps 12 rows apart

  1. #1
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Macro that replaces repeating the same steps 12 rows apart

    I have a macro that works fine I would just like to fine tune it so that it works more efficiently.
    Currently it completes the same step 19 times (every 12th row), however, most of the time it only needs to complete 12 times but can vary from 6 to 33.

    Any help in shortening the code to reflect the repeat steps and additional code to find the last row in the range and only complete until it reaches the last row would be much appreciated.



    A snippet of the code:

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro that replaces repeating the same steps 12 rows apart

    Your code is not very clear. Maybe you can attach a sample file and explain what you want to do.

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Macro that replaces repeating the same steps 12 rows apart

    I have attached a sample file that does what I need to do.
    As you can see from the sample, one part of the code repeats the same step over and over every 12th row.
    As you can also see from the sample, sometimes the code runs on empty cells. I would like the code to run to the end of the data and stop. The end cell of the data varies from sheet to sheet.

    Any help appreciated.
    Thx
    Attached Files Attached Files

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro that replaces repeating the same steps 12 rows apart

    Can you upload your data before running the macro?

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro that replaces repeating the same steps 12 rows apart

    Perhaps this will give you a start or at least some ideas.

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Macro that replaces repeating the same steps 12 rows apart

    Quote Originally Posted by arlu1201 View Post
    Can you upload your data before running the macro?
    Attached file contains the data before I run the macro and the data after I run the macro.
    Attached Files Attached Files

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro that replaces repeating the same steps 12 rows apart

    The code I posted produces the results in the 'Data After Macro' worksheet.

  8. #8
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Macro that replaces repeating the same steps 12 rows apart

    Quote Originally Posted by Norie View Post
    The code I posted produces the results in the 'Data After Macro' worksheet.
    Thanks Norie,

    Your code works beautifully.

    2 related issues:

    1. I want to copy down a4 and b4 to the end of the range (the last used cell in column 'c' would do the trick I think?) instead of copying to the predetermined row229...I am not sure how I can do this.
    2. I have an issue with the 'while' argument. Sometimes there are no values (blank cells) in the middle of the range so the code will see this as the end even though there are other values further down....is it possible to put in an argument that says wait until 'x' number of blank cells are found before ending?? I have tried changing the 'while rangesrc.cells(1,1) parameter without any luck!

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro that replaces repeating the same steps 12 rows apart

    1 I thought that might be a problem but it should be easy to fix.

    2 That might/might not be a bit harder - I based the code I posted on your code not the data.

    What would you want to happen if there are empty rows between data?

    Should the data move up?

  10. #10
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Macro that replaces repeating the same steps 12 rows apart

    1. I just added that at the end because it approximates 19 repetitions of the other code! I have tried to code find last cell in column 'c' but it screwed up the rest of the data so I left it as a manual copy paste to a predetermined row.

    2. I used your code and applied it to copy some other parts of my data which is not always there. If you can see in the finished data each row represents one string...sometimes there are blanks in the raw data but I still want to copy whatever data that belongs to the string, even if that means having some blank columns in the string.

    Your help is much appreciated.
    Last edited by anrichards22; 11-07-2012 at 06:26 PM.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro that replaces repeating the same steps 12 rows apart

    I won't be able to have another look until tomorrow I'm afraid.

  12. #12
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Macro that replaces repeating the same steps 12 rows apart

    You have been a great help!

    When you find the time please take another look and post a reply.

    Thanks again.

+ 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