+ Reply to Thread
Results 1 to 2 of 2

Cutting out the middleman in macro code

  1. #1
    Registered User
    Join Date
    07-28-2021
    Location
    Illinois
    MS-Off Ver
    365
    Posts
    2

    Cutting out the middleman in macro code

    Hi there. So I am fairly new to vba but I have had quite the crash course in it at my work. I've been going through a massive macro that has been used by my company for almost a decade. It is barely holding together so I have been slowly trying to improve it. There is one area I think might be able to be optimized but I am not sure, so I wanted to ask. Basically, this macro uses three IF statements that I think could be combined to cut out the middle step. First, it looks at data in one column and has a bunch of IF statements saying to check one column for certain values and if they match, go to another part of the code. At that designated part of the code it writes a certain number (there are 40 possible numbers). This is looped for all rows. Then, another IF statement checks the newly entered numbers made by that set of code and for each number to perform an action to another column. I am thinking, wouldn't it be simpler to cut out the step where it writes the numbers and instead use the first IF statement to go directly to the last one that modifies the data.

    For example, right now it looks something like this:
    Keep in mind there are about 40 of these statements all pretty much identical just with different numbers depending on what the WC value is.

    If WC = "138-5733" Or WC = "138-5230" Then GoTo 1
    1 Cells(Row, 11) = 6
    If Cells(Row, 11) = 6 Then GoTo 506
    506 If myday = 2 Then cellduedate = ordduedate - 10


    So I'm wondering if there would be any harm in changing it to be:

    If WC = "138-5733" Or WC = "138-5230" Then GoTo 506
    506 If myday = 2 Then cellduedate = ordduedate - 10

    Could anyone tell me if there might be any unintended consequences to making this change? Would it even help? The numbers that are added in column 11 using this code are never used again in the macro so leaving them out will not have an effect on the rest of the macro.
    Thank you!

  2. #2
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Cutting out the middleman in macro code

    hard to say what may happen, make a copy of the file, make the change and run the macro and see if everything works as expected.
    Also the change you are thinking of doing should work just the same, UNLESS that value of 6 is being used by anything else in the macro or as an expected value in that cell.
    If you find the suggestion or solution helpful, please consider adding reputation to the post.

+ 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. VBA macro cutting off information
    By RPA_Legend in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-05-2021, 06:22 PM
  2. cutting a code in 2 lines
    By RJ1969 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-16-2020, 04:07 PM
  3. VBA code for cutting and pasting a table of varying rows from one worksheet to another
    By Mellitus82 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-20-2019, 10:29 AM
  4. Macro for cutting text
    By michal99 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-14-2015, 08:55 PM
  5. Cutting & Pasting Macro
    By scruz9 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-16-2014, 12:39 PM
  6. VBA Code for cutting character lenghts into another cell
    By ziemann82 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-01-2013, 08:54 AM
  7. [SOLVED] Macro for cutting and pasting by criteria
    By harrydnyc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2011, 12:30 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