+ Reply to Thread
Results 1 to 8 of 8

Can anyone advise on tidying up code?

  1. #1
    Registered User
    Join Date
    08-07-2006
    Posts
    5

    Can anyone advise on tidying up code?

    Hi,

    I am new to VBA code and looking for a little advice on tidying up some code I have been recording.

    Is there better ways that some of this could have been written rather than recorded?

    What this is doing is taking a table of data and reseting filtered items as a default on exit (it also moves to that sheet if not selected)

    Thanks in advance!

    Paul



    Please Login or Register  to view this content.
    Moderator Note:

    Pls use code tags around your code next time as per forum rules.

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Can anyone advise on tidying up code?

    Hi Paul,

    This is how I would write the code

    Please Login or Register  to view this content.
    No Select/Activate but using With - End With and using Thisworkbook as opposed to ActiveWorkbook. Mostly my own preferences
    If you like my contribution click the star icon!

  3. #3
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Can anyone advise on tidying up code?

    @OllieB

    Your version has some Range and Cells that need a worksheet owner if you do not activate the sheet.

  4. #4
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Can anyone advise on tidying up code?

    @Izandol,

    Yup.

    Please Login or Register  to view this content.
    without the actual workbook it is too much work to test

  5. #5
    Registered User
    Join Date
    08-07-2006
    Posts
    5

    Re: Can anyone advise on tidying up code?

    Thank you for that, that is alot tidier, one point though.

    I had the "Sheets("Data").Select" at the start so that if any users were on another tab that it always defaulted back to this tab?

    What would be the best way to get it to do this?

    Cheers
    Last edited by whitieklf; 09-30-2013 at 09:35 AM.

  6. #6
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Can anyone advise on tidying up code?

    Add the instruction

    Please Login or Register  to view this content.
    anywhere in the block delimited by With and End With

  7. #7
    Registered User
    Join Date
    08-07-2006
    Posts
    5

    Re: Can anyone advise on tidying up code?

    Thank you

  8. #8
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Can anyone advise on tidying up code?

    Based on your last post in this thread, its apparent that you are satisfied with the solution(s) you've received and have solved your question, but you haven't marked your thread as "SOLVED",as per our Forum Rule #9. I will do it for you this time.

    In future, to mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

+ 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. tidying up code
    By tryer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-14-2011, 10:03 AM
  2. code tidying
    By stevesunfold in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-26-2008, 05:23 PM
  3. Tidying/ Simplifying Code
    By bomberchia in forum Excel General
    Replies: 6
    Last Post: 11-29-2008, 06:16 AM
  4. [SOLVED] Help with tidying up code please
    By Andy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-10-2005, 01:00 AM
  5. tidying up code and refering macros
    By philbennison in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-12-2005, 08:32 AM

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