+ Reply to Thread
Results 1 to 25 of 25

Make recorded macro loop

  1. #1
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Make recorded macro loop

    I have recorded the below macro but I need it to loop until there is nothing left in the last column.

    Can anyone assist?

    Thanks,

    Please Login or Register  to view this content.
    Moderator's Edit: Use code tags when posting code. To do so in future, select the code and click on the # icon at the top of your post window.
    Last edited by arlu1201; 01-04-2013 at 02:45 PM.

  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: Make recorded macro loop

    It will be good if you explain what your code is trying to do. Sometimes while recording the macro, if you click on the wrong cell(s), it still includes it and this will not help us in editing the code for you.
    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
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Re: Make recorded macro loop

    Quote Originally Posted by arlu1201 View Post
    It will be good if you explain what your code is trying to do. Sometimes while recording the macro, if you click on the wrong cell(s), it still includes it and this will not help us in editing the code for you.
    Well it's a little hard to say but I'm converting columns to rows. Example column E has a header row and then below that are several fees. I'm moving the fees into column b and then in column C I'm copying the header row for all the fees for that column and the next columns goes right beneth the prior column in the rows. The current macro is working great but I just don't know how to get it to keeping going to the next column until they have all been converted to rows.

  4. #4
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Re: Make recorded macro loop

    Quote Originally Posted by cowannbell View Post
    Well it's a little hard to say but I'm converting columns to rows. Example column E has a header row and then below that are several fees. I'm moving the fees into column b and then in column C I'm copying the header row for all the fees for that column and the next columns goes right beneth the prior column in the rows. The current macro is working great but I just don't know how to get it to keeping going to the next column until they have all been converted to rows.
    Please Login or Register  to view this content.

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

    Re: Make recorded macro loop

    Do you have a sample file that you can attach?

    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.

  6. #6
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Re: Make recorded macro loop

    See sample below.
    Attached Files Attached Files

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

    Re: Make recorded macro loop

    Try this one

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Re: Make recorded macro loop

    it errors on this line

    a = Sheets("Before").Range("a2").CurrentRegion

  9. #9
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Re: Make recorded macro loop

    error is script out of range

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

    Re: Make recorded macro loop

    Not according to the attached. You should have a workbook called "Before", or tell me the name of your worksheet and will change it.

  11. #11
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Re: Make recorded macro loop

    Okay, I used the sheet that I had sent you and it works but just for the first two schs/columns. The example I sent you only had two schs/columns but the work book that I work with can have many that need to be converted. This macro did fees for the two columns over but not for any of the other columsn on the sheet. So on the after sheet i column b only two schs listed in column c has fees listed in column b. It did not pull the fees for all the other columns.

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

    Re: Make recorded macro loop

    You need to post your new sample book, and I will adjust the code accordingly. I can't adjust my code with out seeing your new request. The code worked on the sample provided.

  13. #13
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Re: Make recorded macro loop

    There is no difference in the one I sent you and the one I'm working other than there are more columns that need to be converted. Your code works for column C but doesn't work for column B in the after sheet except for the first two columns in the before sheet.

  14. #14
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Re: Make recorded macro loop

    Please see new sheet 2 and you will see what the macro did. It did column c in the after sheet correctly but not column B.

    Thanks.
    Attached Files Attached Files

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

    Re: Make recorded macro loop

    You have 3 columns in your before sheet, so I do not know which columns you are reffering to. Could you please explain whcih columns need to be converted and where? What is missing from my code?

  16. #16
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Re: Make recorded macro loop

    Let's look at column b which has a header of DP4KA below that are the fees that go with that code. If you look in the after sheet you will not see the fees in Column B except for DP4KA and DP4KB where there should be fees showing for all of the columns starting with Column B in the Before Sheet. Your macro did take the column headings and put them all in column C in the after sheet which is correct it just doesn't pull the fees over that go with that column.

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

    Re: Make recorded macro loop

    Please see attacched. You need to show me what is missing, I do not know which are your fees, I can only go by the data type. You need to show me where each row and column should go.
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Re: Make recorded macro loop

    Please look at the 2nd file that I attached. The before sheet has many more columns. The amount of columns after columns a and b can change at any time. There could be 10 or 30 or so on. If you run the macro that you sent me on the 2nd file that I attached, you will see what is missing or if you just look at the one I sent you on the after sheet you will see what is missing starting on row 64 column B.

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

    Re: Make recorded macro loop

    Cow,
    Sorry! I did not see your attachment. I do not know how I missed it and subsequently asked you to attach again. Here is the amended code. It is not good for the eye to see, but it does the job. If I had the time, I would have written a short code.

    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Re: Make recorded macro loop

    Please see attached after the first two conversions from the before page, you will see that in the after page, the fee which are in column b in the after sheet are not in order and if you go to the end of the page you will see that not even all of the fees in column b are pulled over.
    Attached Files Attached Files

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

    Re: Make recorded macro loop

    I does on my sample. Please see attached
    Attached Files Attached Files

  22. #22
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Re: Make recorded macro loop

    No it doesn't. Look at the after tab and line 33. You will see DP6NA and it should be DP6NB with 4 in column b.

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

    Re: Make recorded macro loop

    Okay!
    Change this line of the code

    Please Login or Register  to view this content.
    INTO
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by AB33; 01-11-2013 at 08:58 AM.

  24. #24
    Registered User
    Join Date
    06-22-2005
    Posts
    19

    Re: Make recorded macro loop

    That did it, thanks so much.

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

    Re: Make recorded macro loop

    You are welcome!
    Could you please now close this post as solved by going in to the top right hand of this page-Choose solved from the "Thread Tools" drop down menu?

+ 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