+ Reply to Thread
Results 1 to 9 of 9

Help cleaning up a macro

  1. #1
    Registered User
    Join Date
    08-22-2011
    Location
    St. Paul, MN
    MS-Off Ver
    Excel 2010
    Posts
    13

    Help cleaning up a macro

    I have a macro that works, but it takes a while to get the job done and the screen also flashes constantly as it runs. The macro finds all 0's or 1's in a specific column and then copies the entire row if a 0 or 1 is found. It then pastes all of the rows into a new worksheet, which is exactly what I want it to do. Here's the code:

    Please Login or Register  to view this content.
    If there is any way this could be cleaned up so it can complete the job quicker and without the screen blinking, it would be greatly appreciated if you would give me your insights!!
    Last edited by gugg7378; 08-23-2011 at 10:38 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Help cleaning up a macro

    Activating & Selecting ranges/sheets will slow the code & is not necessary and causes the screen blinking.

    The whole code is full of unnecessary loops. Where is the activecell referred to on the data sheet? If the wrong cell is selected then it can't work

    It would be better if you stated exactly what you want to do then someone can write more efficient code than you have at the moment
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    08-22-2011
    Location
    St. Paul, MN
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Help cleaning up a macro

    Thanks for the help. I'll try to explain it a bit better. I can't upload the exact stuff I'm working on because it contains private info, but I've uploaded a dummy sheet that should help with the explanation.

    I want the macro to search in column BI for any blank cells or for any cells containing a 1. I then want those entire rows to be copied into a different worksheet so only those records are available. I know I can do this by autofilter, but I was asked to come up with a way to automate the process.

    So, just for clarity, in the example that I have provided, I want the macro to locate the blanks and 1's in column BI (the first two rows), and then select those entire rows and paste them into the second worksheet.

    Thanks for the help!
    Attached Files Attached Files

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Help cleaning up a macro

    You should automate AutoFilter in a macro, see my code here as a guide.

  5. #5
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Help cleaning up a macro

    Hi gugg7378, try using this code
    Please Login or Register  to view this content.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  6. #6
    Registered User
    Join Date
    08-22-2011
    Location
    St. Paul, MN
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Help cleaning up a macro

    royUK, I looked at the code you directed me to, but couldn't figure much out from it. Does that code tell the sheet to delete rows? If so, I don't want any rows to be deleted. Just copied and pasted into a new workbook.

    Mordred, I tried the code you suggested, but it comes up with an error saying the subscript is out of range.

    Thanks for the quick responses.

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Help cleaning up a macro

    Hi gugg7378,

    I just tried Mordred's code on the workbook you posted and it works. What error are you getting and is it on this workbook or another?

    abousetta

  8. #8
    Registered User
    Join Date
    08-22-2011
    Location
    St. Paul, MN
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Help cleaning up a macro

    Sorry, stupid mistake. I had one of my worksheets named wrong in a different workbook, which was causing the issue. Thanks a ton, it works great and MUCH faster than the way I originally had it!

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Help cleaning up a macro

    I said use the code as a guide. It does delete rows but you can change that. It will be much faster than a Loop

+ 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