+ Reply to Thread
Results 1 to 7 of 7

user-determined adding of cell values in a column: code breaks down after 2 cells

  1. #1
    Registered User
    Join Date
    11-08-2016
    Location
    Munich, Germany
    MS-Off Ver
    2010
    Posts
    28

    user-determined adding of cell values in a column: code breaks down after 2 cells

    Hi everyone,

    I have coded a Macro where a user can decide which cell values belong together, these values should then be added in the next column. A maximum of 5 cells should be added together. The user should use characters in the second column to indicate which values belong together. If there is no indication, the original value of the left column should be just copied to the right column. Somehow, the code only recognizes only groups of 2- maybe someone can help?

    Here is how it looks like when it breaks down:
    Please Login or Register  to view this content.
    Here is the code:

    Please Login or Register  to view this content.
    Thank you so much for your help!

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: user-determined adding of cell values in a column: code breaks down after 2 cells

    The chain comparison for 3-5 processes don't work as you expect. you need to rewrite it.
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Registered User
    Join Date
    11-08-2016
    Location
    Munich, Germany
    MS-Off Ver
    2010
    Posts
    28

    Re: user-determined adding of cell values in a column: code breaks down after 2 cells

    Hi Buran,

    thanks for your reply! I am fairly new to VBA, may I ask how I can compare more than one cell to check whether they have the same value?

  4. #4
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: user-determined adding of cell values in a column: code breaks down after 2 cells

    the most basic change would be
    Please Login or Register  to view this content.
    There are better ways too, but if you lack VBA experience this will do

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

    Re: user-determined adding of cell values in a column: code breaks down after 2 cells

    Formula in C2
    =IF(B2<>"",IF(COUNTIF(B$2:B2,B2)=1,SUMIF($B$2:$B$17,B2,$A$2:$A$17),""),A2)

    VBA
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-08-2016
    Location
    Munich, Germany
    MS-Off Ver
    2010
    Posts
    28
    Thanks Buran, i just thought of the same change, too! :D

    Since I want to learn a bit more about vba, i am curious what more ways there are to have the code more efficient? If you have time, i would really appreciate some new knowledge!

    Edit: oh i will first check what jindon has just submitted!
    Last edited by simz92; 01-22-2017 at 04:40 AM.

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: user-determined adding of cell values in a column: code breaks down after 2 cells

    If you have headers in row 1, put

    =IF(B2="",A2,IF(COUNTIF(B$1:B2,B2)=1,COUNTIF(A:A,B2),"")) in C2 and drag down.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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 code and Adding dynamic Page Breaks
    By scott micklo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2016, 03:11 PM
  2. Replies: 2
    Last Post: 05-19-2015, 08:50 AM
  3. Macro for adding a number to a cell determined by a vlookup
    By smithpgr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2014, 07:31 PM
  4. Replies: 0
    Last Post: 11-27-2013, 09:11 PM
  5. [SOLVED] Construct a formula on a pre-determined cell for a pre-determined duration of cells
    By Shaun Gemiver in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-03-2013, 11:14 AM
  6. Fill cells determined by Time Value selection w/user form
    By ShannonHowell in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-12-2012, 09:56 PM
  7. Adding Value of Cells, but Cell Determined by Dropdown List
    By concretetsunami in forum Excel General
    Replies: 4
    Last Post: 03-09-2010, 04:19 PM

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