+ Reply to Thread
Results 1 to 7 of 7

Speeding up a macro that finds information and copies and pastes it.

  1. #1
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Speeding up a macro that finds information and copies and pastes it.

    Hi All,

    Hoping you can help me with this one. I have attached the workbook with the code in it. Everything works fine in the macro but as you can see I am no expert with vba! I have manually told it to select every sheet and cell that is needed and therefore the macro runs a lot slower.

    A seperate query about the same spreadsheet, this obviously only works on the first column next to the name (as that is what I reference for the cells) so if you wanted a Monday rota it would be fine. Have you any suggestions how I can make this work dependant on what day of the week you want?

    For example cell J4 references the day and I thought this code below might do it, but I had no luck!

    Please Login or Register  to view this content.
    but that just brought errors up in the code. Obviously all of the cell references were changed to 'c' but I have now changed them back.

    Of course another way to do it is using the above code to decide which Module to fire and save each day in a seperate Module but I do worry about that slowing the macro down even further!

    Any help is much appreciated.

    Regards

    Danny
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    09-05-2012
    Location
    Dallas, Tx
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Speeding up a macro that finds information and copies and pastes it.

    One way to speed it up is to turn off the screen updating before running it,
    at the top of your macro add this
    Please Login or Register  to view this content.
    then turning back on at the end by adding the before the end.
    Please Login or Register  to view this content.

    <----If this helps you please click the star.
    http://excelevangelist.blogspot.com/

  3. #3
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Speeding up a macro that finds information and copies and pastes it.

    If you are interested in reducing the number of lines for IF statements, this will
    give you the same results for the variable c:
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,887

    Re: Speeding up a macro that finds information and copies and pastes it.

    I started looking at your code and then I got carried away.
    Your code was a mess yes, but at least you tried. Not everybody does that.
    See if this thing that I made works for you.
    Attached Files Attached Files
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

  5. #5
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: Speeding up a macro that finds information and copies and pastes it.

    I will always try, I want to learn VBA but stringing a lot of basic commands together seems to be easier to remember. Any tips on how to learn VBA 'more advanced' codes. What I mean is telling it to copy and paste without having to select everything and ones like that.

    Thank you to all of you for your help.

    I have done stars and solved .

    Regards

    Danny

  6. #6
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,887

    Re: Speeding up a macro that finds information and copies and pastes it.

    Thanks DannyJ! Tips to learn VBA? Well for me it just sort of happened over time. It takes time. If you are interested (check!) and fiddle with it a lot it will happen.
    Make small macro's just to test functions and features as you need them.
    Actually, make a lot of small macro's to test things out.
    Use the macro recorder a lot but make sure you strip that code to the bare minimum before using it, otherwise it is just confusing.
    Use things like Debug.Print variableA or MsgBox variableA a lot. It can be used to indicate if a certain part of the code executes. Or type things like ?activecell.address in the immediate window.
    Make sure to Tab your code to make it readable.
    Learn to use breakpoints (F9) and step through the code (F8).
    A book like one of the Walkenbach books on VBA can be a really good help even if things are available on line. Things are usually explained better in books.
    Look at other people's code.


    I recall when I first took the step to learn VBA one of the first things I got stuck on was the Copy Paste. Now 6 years and a thousand macros later I'm still not sure how to use it. Turns out that it's not very useful feature. I know that if I need it I just google it, run a couple of test macro's and then I'll have it figured out. Until next time...

    Other things like application.screenupdating that MarkinTX mentions is a thing to always remember. I didn't use it in Rota, it wasn't needed but I sure use it a lot in my macros in general.

    The smart formula of xLJer is not something I would just type in from memory but I have an idea of what is possible and I'll go from there. I hope I remember the basic idea of this one though because that was new to me.

    I just recalled now that I did use copy paste at work a couple of weeks ago to copy a range complete with formulas. There it was definitely useful. In your rota application I found no use for it. Look in my code and you'll see.

  7. #7
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Slough
    MS-Off Ver
    Excel 2007
    Posts
    469

    Re: Speeding up a macro that finds information and copies and pastes it.

    Yes I did have a skim through your code. It was all linked cells rather than copy and pasting, sometimes the biggest downfall for me is that I think too methodically and go through it step by step which results in more lines of code than necessary! Thanks a lot for taking the time to reply in depth though it is much appreciated. From what I gather from this it is more about understandnig VBA than remembering it. In the sense that if you can understand someone elses code it can be copy and pasted and easily edited to what is necessary.

    Thanks again for your time.

    Regards

    Danny

+ 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