+ Reply to Thread
Results 1 to 4 of 4

Clean up code

  1. #1
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    245

    Clean up code

    Hello -

    See code in Module 1 of attached workbook. The same procedure needs to run in cells H3:H5 based on values selected in cells A3:A5. As a new student of VBA, I'm trying to figure out how to shorten this code?

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Clean up code

    Hello Grilleman,

    Do really need to do this VBA? This is much easier to do using formulas.

    I removed all the code and then added a new named range "Required" with the values needed for each part (1 or 2). In column in column "H", the following formula was added and dragged down:

    =D3*E3*INDEX(List:Required,MATCH(A3,List,0),2)
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Clean up code

    Please Login or Register  to view this content.
    The above should work as a replacement for the sub you did.

    edit: Updated the code to search the entire column A for values and put the corresponding value into column H.
    Last edited by 111StepsAhead; 04-11-2012 at 01:22 PM.

  4. #4
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    245

    Re: Clean up code

    Awesome - works great! Now I just need study what you did differently to see if I can understand it. Thank you very much.

+ 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