+ Reply to Thread
Results 1 to 9 of 9

Need Help Optimizing Code

  1. #1
    Registered User
    Join Date
    10-19-2017
    Location
    Plover, WI
    MS-Off Ver
    2016
    Posts
    9

    Need Help Optimizing Code

    For the past week I have been hard at work basically learning VBA and macros and such for a project at work. My efforts , to my surprise, have been quite fruitful. Though I cant help but think my code is sloppy and could likely be optimized to run faster but I do know the first thing to look for since I've only learn how to do everything here in one particular way, also I'm deathly afraid of changing anything at this point and bringing it all crashing down. Could some of you excel masters have a look-see at my script and let me know if there is room for improvement

    The file works like this:
    -operator opens file and if new a part is being produces he goes into the Tool List sheet and populates it to the best of his ability (in reality only column A with the numbers is required)
    -when the operator has to replace a tool in the machine he does so, then goes into the excel file and under the Input sheet types the "tool number", "work order", "running total of parts" and "notes"
    -clicking the "add" button enters this information into a table in the Tool Data sheet from which the pivot table and chart pulls from and updates the descriptive statistics.

    the whole point on this is to give the operator a feel for how long the tools in his machine are lasting during a particular work order

    I have attached the file for you feedback along with some sample data already put in.
    Attached Files Attached Files
    Last edited by joey2point0; 10-23-2017 at 03:50 PM. Reason: Forgot Attachment

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,259

    Re: Need Help Optimizing Code

    When I read the word 'operator' it probably means a few people will be working with this file.
    Giving them access to your sheets directly is a dangerous game you're playing because at some point they'll start messing around to correct an error they typed or ... ending up destroying your entire file.
    You will have to protect your sheets thouroughly so they don't get access where they shouldn't (just to protect your formulas and such) or have a look at building Userforms so direct access isn't needed.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Registered User
    Join Date
    10-19-2017
    Location
    Plover, WI
    MS-Off Ver
    2016
    Posts
    9

    Re: Need Help Optimizing Code

    bakerman2,

    Is it possible to protect only certain cells on a particular worksheet to allow the operator to only use the cells where he/she would enter data?

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,259

    Re: Need Help Optimizing Code

    Select the cells they need to fill. Right click and select Properties. Select tab Protection and unlock these cells.
    Now protect your worksheet so they can only select unlocked cells.

  5. #5
    Registered User
    Join Date
    10-19-2017
    Location
    Plover, WI
    MS-Off Ver
    2016
    Posts
    9

    Re: Need Help Optimizing Code

    I have done what you said and the same for the buttons, but when I protect the sheet and click the "Add" button the information gets added but wont clear out form the input cells.

  6. #6
    Registered User
    Join Date
    03-03-2015
    Location
    England
    MS-Off Ver
    2013
    Posts
    32

    Re: Need Help Optimizing Code

    Add additional code to the macro your button is calling. Once it has added the input data to the relevant table, add something along the lines of:

    Please Login or Register  to view this content.
    Or, if you are using a textbox:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-19-2017
    Location
    Plover, WI
    MS-Off Ver
    2016
    Posts
    9

    Re: Need Help Optimizing Code

    It works, but throws an "Application-defined or object-defined error"

    debugging highlights the additional line of code

  8. #8
    Registered User
    Join Date
    10-19-2017
    Location
    Plover, WI
    MS-Off Ver
    2016
    Posts
    9

    Re: Need Help Optimizing Code

    Alright, so I'm not sure what i have done, but it appears to be working now!

  9. #9
    Registered User
    Join Date
    03-03-2015
    Location
    England
    MS-Off Ver
    2013
    Posts
    32

    Re: Need Help Optimizing Code

    Quote Originally Posted by joey2point0 View Post
    Alright, so I'm not sure what i have done, but it appears to be working now!
    Often ends that way!

+ 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. Help Optimizing Code
    By tasugie in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-29-2013, 06:12 PM
  2. need help optimizing my code
    By NirXY in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-11-2013, 11:49 AM
  3. Optimizing Code
    By tucanj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2013, 11:08 PM
  4. Optimizing Code
    By dcgrove in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-23-2012, 11:20 AM
  5. Optimizing the Vlookup code in VB. Repitive code with different referencing range.
    By raknahs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2010, 05:03 PM
  6. Need Help Optimizing Some Code
    By jackb1117 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-12-2009, 07:50 PM
  7. Optimizing code
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-06-2009, 11:40 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