+ Reply to Thread
Results 1 to 7 of 7

Incorporate Loop Function In Recorded Macro

  1. #1
    Registered User
    Join Date
    06-02-2014
    Location
    Victoria, Australia
    MS-Off Ver
    Office 2007
    Posts
    6

    Incorporate Loop Function In Recorded Macro

    Hi,

    I have a CSV file which has data in the incorrect columns when the report has been created as per attachment.

    I have recorded the macro below which I will need to select a cell in column N before activating the macro, instead of activating the macro x amount of times until I've gone through the whole workbook, I would like to be able to press the macro once and the whole sheet has been done then go to cell A1 if possible.

    Please Login or Register  to view this content.
    Thank you very much for looking into this, it is greatly appreciated.
    Regards,
    Attached Files Attached Files
    Last edited by tarktran; 12-27-2014 at 11:40 PM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Incorporate Loop Function In Recorded Macro

    Please update your profile as necessary to properly reflect the exact version(s) of Excel your question relates to. Members tailor answers based on your Excel version.
    ALSO
    Your post does not comply with Rule 3 of our Forum
    RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Incorporate Loop Function In Recorded Macro

    Perhaps change

    Please Login or Register  to view this content.
    by
    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Incorporate Loop Function In Recorded Macro

    Your code is hard to understand, what's it supposed to do?

  5. #5
    Registered User
    Join Date
    06-02-2014
    Location
    Victoria, Australia
    MS-Off Ver
    Office 2007
    Posts
    6

    Re: Incorporate Loop Function In Recorded Macro

    In the CSV file attached "DOR REPORT.csv" the data should only be in the columns A to M and O, it shouldn't appear in any columns (everything in columns A to F is all correct).

    What the code does is :

    - CTRL + DOWN ARROW (reaches a row that is displaying data in the wrong columns as nothing should appear in the N column)
    - CTRL + SHIFT + LEFT ARROW
    - CTRL + F and search for "CONT_ADV" in that row (which is why the previous step was done to find CONT_ADV for that row)
    - Press ESCAPE to close the "Find and Replace" prompt
    - Click the LEFT ARROW (twice)
    - CTRL + SHIFT + RIGHT ARROW (twice) which in this spreadsheet it would highlight the data as per image below:

    Data Selected.png

    - Cut that data, go to column G in the same row and paste it

    I want to be able to activate the macro once so all the data on the spreadsheet is in the correct columns instead of pressing it x amount of times to go through the whole workbook.

    The code doesn't have to stick to this, this is purely what I have recorded.

    I hope this is a better and clearer explanation, thank you.
    Attached Images Attached Images
    Attached Files Attached Files

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Incorporate Loop Function In Recorded Macro

    It looks like you are just deleting the date in column I.
    This code will find data in column N, then move over 5 cells and delete the cell, moving the rest of the row over.

    Please Login or Register  to view this content.
    Last edited by davesexcel; 12-28-2014 at 09:00 AM.

  7. #7
    Registered User
    Join Date
    06-02-2014
    Location
    Victoria, Australia
    MS-Off Ver
    Office 2007
    Posts
    6

    Re: Incorporate Loop Function In Recorded Macro

    Thank you for responding and hope you had an enjoyable holidays.

    Only adjustment I made to your code is:

    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    With the code above however, I will have to activate it multiple times for all the data to be in the correct columns as there may be more data that may have shifted to the right as per image below:

    Capture.JPG

    I rushed the last reply, hopefully this should be more clearer:

    - The data in RED needs to shift to the left according to what I have written in column T, over the ORANGE data;
    - GREEN is correct data and doesn't require to be shifted. So as you see in row 11 of the image, the data is where it should exactly be;

    The misaligned data could appear anywhere in a CSV spreadsheet that may contain over 5000 rows of data which an example of the workbook be in the opening post "DOR_180914.csv‎", the data could also shift more to the right in comparison to the image.

    End result should look like the image below:

    Capture2.JPG
    Attached Images Attached Images

+ 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] Reduce code recorded from a macro in excel vba using a loop
    By VBA-Excel_Newbie in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-24-2014, 05:00 AM
  2. [SOLVED] Recorded Pivot Table Macro Doesn't Do What I Recorded!
    By diakonos1984 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-26-2013, 11:01 AM
  3. Make recorded macro loop
    By cowannbell in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 01-11-2013, 09:53 AM
  4. How to create a loop for recorded macro?
    By Partisano in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-30-2012, 12:03 PM
  5. [SOLVED] Incorporate (xlCellTypeVisible) into For..Next loop
    By Gard5096 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-17-2012, 12:55 PM

Tags for this Thread

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