+ Reply to Thread
Results 1 to 8 of 8

Simplify code that's too long

  1. #1
    Registered User
    Join Date
    07-10-2019
    Location
    New York, NY
    MS-Off Ver
    MS Office 2016
    Posts
    27

    Simplify code that's too long

    I have a VBA code that is too long (after a certain point it stops working) and I'm hoping that there's a way to simplify it to fix this issue. What the code does is it replaces any empty cells in a given range with a default formula. Here is the code I'm currently using:

    Please Login or Register  to view this content.
    And so on...

    So the formula is repeated for several columns in each section, then changes slightly for the next section:
    Please Login or Register  to view this content.
    But is there a way to simplify this formula so I don't necessarily need one section of code for each column since they all use basically the same formula? I've tried using "myCell.Column" for the column designation, but that doesn't seem to work. Any other suggestions?

    Any advice would be greatly appreciated!

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,513

    Re: Simplify code that's too long

    Replace all of the first bunch with
    Please Login or Register  to view this content.
    and all of the second bunch with
    Please Login or Register  to view this content.
    Make sure to try it on a copy of your workbook first.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Simplify code that's too long

    Perhaps
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-10-2019
    Location
    New York, NY
    MS-Off Ver
    MS Office 2016
    Posts
    27

    Re: Simplify code that's too long

    This code seems to work for the first section, but when I tried to add in the code for next section it didn't work. Please tell me where I'm going wrong.

    Here is the code I'm currently using:
    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Simplify code that's too long

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-10-2019
    Location
    New York, NY
    MS-Off Ver
    MS Office 2016
    Posts
    27

    Re: Simplify code that's too long

    Sorry if I was unclear. I actually have 12 sections, not just 2, so I don't think this code will work either.

    Here is the full detail of what I'm looking to do:
    - For cells AA9:AL33 I want the blank cell's formula to be =IF($G(cell row)="Yes",$Z(cell row)/12,"")
    - For cells AO9:AZ33 I want the blank cell's formula to be =IF($G(cell row)="Yes",$AN(cell row)/12,"")
    - For cells BC9:BN33 I want the blank cell's formula to be =IF($G(cell row)="Yes",$BB(cell row)/12,"")
    - For cells BQ9:CB33 I want the blank cell's formula to be =IF($G(cell row)="Yes",$BP(cell row)/12,"")
    - For cells CE9:CP33 I want the blank cell's formula to be =IF($G(cell row)="Yes",$CD(cell row)/12,"")
    - For cells CS9:DD33 I want the blank cell's formula to be =IF($G(cell row)="Yes",$CR(cell row)/12,"")
    - For cells DG9:DR33 I want the blank cell's formula to be =IF($G(cell row)="Yes",$DF(cell row)/12,"")
    - For cells DU9:EF33 I want the blank cell's formula to be =IF($G(cell row)="Yes",$DT(cell row)/12,"")
    - For cells EI9:ET33 I want the blank cell's formula to be =IF($G(cell row)="Yes",$EH(cell row)/12,"")
    - For cells EW9:FH33 I want the blank cell's formula to be =IF($G(cell row)="Yes",$EV(cell row)/12,"")
    - For cells FK9:FV33 I want the blank cell's formula to be =IF($G(cell row)="Yes",$FJ(cell row)/12,"")
    - For cells FY9:GJ33 I want the blank cell's formula to be =IF($G(cell row)="Yes",$FX(cell row)/12,"")

    Thanks so much for your assistance!

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: Simplify code that's too long

    You should mention this in your first post, if you can not adjust the code...
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-10-2019
    Location
    New York, NY
    MS-Off Ver
    MS Office 2016
    Posts
    27

    Re: Simplify code that's too long

    That did the trick. Thanks again for your help

+ 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. [SOLVED] Simple VBA code to convert text to number (simplify/fix current code)
    By kenenthpaul0401 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-26-2018, 10:47 AM
  2. [SOLVED] How to Simplify long enough Vlookup formula.
    By herukuncahyono in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-12-2015, 12:27 AM
  3. [SOLVED] Simplify Long Formula
    By Hypernova in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-18-2014, 11:37 PM
  4. [SOLVED] Could anyone help me simplify a very long and drawn out process?
    By Unikron in forum Excel General
    Replies: 13
    Last Post: 11-15-2012, 01:02 PM
  5. Simplify Long Process Function
    By imav in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2011, 02:05 PM
  6. Help Simplify Long Select Case with If/Then
    By garretonufer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-30-2009, 11:57 AM
  7. how to simplify the long formula
    By set giron in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-25-2008, 08:03 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