+ Reply to Thread
Results 1 to 18 of 18

Shortening the code...?

  1. #1
    Forum Contributor
    Join Date
    04-30-2013
    Location
    D.C.
    MS-Off Ver
    Excel 2010
    Posts
    192

    Shortening the code...?

    Hi - I am trying to figure a way to shorten the code and have it run horizontally across the spreadsheet.

    The code would check if there is any data typed in a cell on the farthest right of the spreadsheet to the left in this order (from column EQ to column A). If the cell (row 7) is marked 'X' and then run the code, otherwise, dismiss the code from running. Leave B4="" in the code.

    It would be nice to be able to run the code from Budget!A$7 to Budget!EQ$7 if possible without making the code any longer... The code below seems to have many duplication due to having to go through each column...

    Please Login or Register  to view this content.
    Any help would be greatly appreciated!

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: Shortening the code...?

    Yes, there are many, many ways to shorten 'the code' - which is actually a formula.

    But your are using values in multiple cells to determine the value returned by the formula, so it would help if you posted a workbook with your formula so that we can ensure that what we propose gives you what you actually want. And I'm not sure what you mean by "have it run horizontally across the spreadsheet" - copy the formula across the sheet, or refer to an entire row or....?
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    04-30-2013
    Location
    D.C.
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Shortening the code...?

    Okay, Bernie. I have attached a sample.

    The main focus is on the DENOMACION part of the spreadsheet (upper right corner) and the tab "Denomacion" where the formula lies in and would need some tidying up.

    Thanks!

    SampleWB.xlsx

  4. #4
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Shortening the code...?

    One idea for you at this point
    Create a table of the months and the code that goes with them and assign the range of months and codes the name Month then use the name in a VLOOKUP.
    A
    B
    1
    Abril AO
    2
    Agosto CK
    3
    Diciembre EG
    4
    Enero E
    5
    Febrero Q
    6
    Julio BY
    7
    Junio BM
    8
    Marzo AC
    9
    Mayo BA
    10
    Noviembre DU
    11
    Octubre DI
    12
    Septiembre CW

    In Denomacion!B2 enter
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    This will replace the much longer formula currently in use.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: Shortening the code...?

    In cell C4 of your sheet Denomacion, try using this:

    =OFFSET(Budget!$A9,0,MATCH($B$1,Budget!$1:$1,FALSE)+COUNTIF(OFFSET(Budget!$A9,0,MATCH($B$1,Budget!$1:$1,FALSE)+2,1,7),"<>"&"")+1)

    But note that you need to enter 0 into your Budget sheet instead of blanks when the value is 0 so that those can be counted.

  6. #6
    Forum Contributor
    Join Date
    04-30-2013
    Location
    D.C.
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Shortening the code...?

    Newdoverman, Thank you for your code. However, it is not what I was looking for. My char(code) is already short enough for that specific code.

    Bernie,
    I have put it in Cell C4 of my sheet Denomacion and it did not work. I do not understand why we are referring to A9 on sheet Budget. help...?

  7. #7
    Forum Contributor
    Join Date
    04-30-2013
    Location
    D.C.
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Shortening the code...?

    Also, I noticed that my code works only for January, but not Feburary. That is what I am trying to figure out how to write a code that will run all the way through all the months. But without writing a too long code.

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: Shortening the code...?

    You need to correct two habits that you have - leaving values blank when they should be 0, and entering spaces to remove values instead of deleting them.

    Here is your workbook with those two issues corrected, with my formulas shown returning the same values as yours.

    SampleWB V2.xlsx

    Note that when you enter values for March, my formulas will continue to work.
    Last edited by Bernie Deitrick; 02-04-2016 at 04:09 PM.

  9. #9
    Forum Contributor
    Join Date
    04-30-2013
    Location
    D.C.
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Shortening the code...?

    Bernie,

    Try that with Feburary. When I mark x in cell S7, the denomacion will not update with either of our codes.

    I am trying to have the code run through every month wherever the X is marked in row 7 and if there is value of 1 or greater in row 6.

  10. #10
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: Shortening the code...?

    Your original formula has nothing to do with x in a cell. It appeared to pick up the last entry within the month blocks of 7 columns, which is what my formula will do, for the month that is shown in cell B1.

  11. #11
    Forum Contributor
    Join Date
    04-30-2013
    Location
    D.C.
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Shortening the code...?

    Yes, it has to do with an X in a cell. If I mark an X in cell J7 on sheet Budget, the denomacion will show $884 on the upper right corner of the sheet Budget same with cell I7 and it will show $930.

    However, if I am to mark an X in cell S7 on sheet Budget, the denomacion will not update.

  12. #12
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: Shortening the code...?

    I think it would better if you described what you have, and how you want to extract data. Is it from the column furthest to the right with an 'x' in row 7?

    In C4, array-enter (enter using Ctrl-Shift-Enter)

    =IF(B4="","",INDEX(Budget!9:9,MAX(IF(Budget!$7:$7="x",COLUMN(Budget!$7:$7)))))
    Last edited by Bernie Deitrick; 02-04-2016 at 05:33 PM.

  13. #13
    Forum Contributor
    Join Date
    04-30-2013
    Location
    D.C.
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Shortening the code...?

    Yes.

    The data would be like this:

    if there is an 'X' in row 7, go to the farthest right 'X' in the row.

    The working formula for Ahorro in the denomacion corner on sheet Budget for column J on the same sheet would be this: =IF(J7>0,J9,"").

    I want the formula to be able to calculate for all the cells in same row for every month in row 9. This will be then copied and pasted from row 9 to 38 and row 42 and 43.

    Hope this is more clear now. =)

  14. #14
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: Shortening the code...?

    This works off the x furthest to the right.

    Sample WB works off x in row 7.xlsx

  15. #15
    Forum Contributor
    Join Date
    04-30-2013
    Location
    D.C.
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Shortening the code...?

    After running a test with the sample WB you attached. It does not work well.

    Thank you for your effort Bernie. If I find a solution, I will update this thread. =)

  16. #16
    Forum Contributor
    Join Date
    04-30-2013
    Location
    D.C.
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Shortening the code...?

    By coming back to this thread, I realized that the workbook did actually work. I just had to fix the sum forumla on the denomacion sheet. However, I would like to include the entire row 7 to track the farthest right "x".

    The "x" would move column by column from column F to column EO.

    What change to the formula should I make in order to make it include the rest of row 7?

    I will work on this while I wait for a response.

    Thanks!

  17. #17
    Forum Contributor
    Join Date
    04-30-2013
    Location
    D.C.
    MS-Off Ver
    Excel 2010
    Posts
    192

    Re: Shortening the code...?

    I see that array formulas are creating issues when I update the Budget sheet because I would then have to go to the denomacion sheet to press CTRL+SHIFT+ENTER to make the array formula run.

    -___-

    I want the entire workbook to automatically update when a value is added/altered.

  18. #18
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: Shortening the code...?

    My example already found the x furthest to the right in row 7.

+ 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] Shortening of VBA code
    By PDBartlett in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-15-2014, 07:10 AM
  2. Shortening Code
    By ScabbyDog in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2012, 11:53 AM
  3. Need help shortening code
    By kainis2k in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-11-2012, 01:01 PM
  4. Help with shortening code
    By CJ-22 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2008, 05:27 PM
  5. Shortening up Code
    By Kr4ftw3rk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2008, 11:38 AM
  6. Shortening Code
    By T De Villiers in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2007, 11:46 AM
  7. Shortening Code
    By T De Villiers in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2007, 11:17 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