+ Reply to Thread
Results 1 to 9 of 9

Calculating differences between cell contents 'by blocks'

  1. #1
    Registered User
    Join Date
    11-09-2012
    Location
    Berlin
    MS-Off Ver
    Excel for Mac
    Posts
    9

    Calculating differences between cell contents 'by blocks'

    Hello everyone,

    I have a little problem with a macro somebody here might be able to help me with. Unfortunately the upload function doesn't seem to work for me so I'll have to describe the sheet. It looks something like this (I hope it's understandable, column C is empty here):
    A B C
    1 68
    1 72
    1 85
    1 91
    1 102
    2 40
    2 54
    2 60
    2 68
    3 76
    3 86
    3 94

    So in column A I have the number of the corresponding 'block' of data, which is ascending by one (it's around 400 in the original file, I just put 1-3 here for this example). In column B I have corresponding data which is always rising from one cell to the next, until the next block starts (e.g 1 -> 2). The length of these blocks varies.

    Now in column C, what I would like to do is calculate a list of the differences of those numbers in column B in regards to the FIRST entry of that block (which would itself be changed to "0"). So in this example the outcome should look something like this:

    A B C
    1 68 0
    1 72 4
    1 85 17
    1 91 23
    1 102 34
    2 40 0
    2 54 14
    2 60 20
    2 68 etc.
    3 76
    3 86
    3 94

    I hope you guys can understand what I mean I'm really new to VBA and I'm having trouble figuring this out, especially how I should program the macro so that it starts from zero again once the block changes (when the number in column A increases by one).

    Any help would be greatly appreciated! Thank you.
    Last edited by TF1985; 11-09-2012 at 07:39 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,799

    Re: Calculating differences between cell contents 'by blocks'

    If you put this formula in C1 and copy down for all data then you don't need VBA. I tested this out on your sample data.

    Please Login or Register  to view this content.
    If for some reason you still need macros, come back, we can do that too.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    11-09-2012
    Location
    Berlin
    MS-Off Ver
    Excel for Mac
    Posts
    9

    Re: Calculating differences between cell contents 'by blocks'

    Hey, thank you!

    But somehow this produces an error message in my case? :/

  4. #4
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Calculating differences between cell contents 'by blocks'

    You don't need VBA for that.

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    See the yellow cells in the attached example.
    Attached Files Attached Files
    Last edited by oeldere; 11-10-2012 at 07:33 AM. Reason: formula added
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  5. #5
    Registered User
    Join Date
    11-09-2012
    Location
    Berlin
    MS-Off Ver
    Excel for Mac
    Posts
    9

    Re: Calculating differences between cell contents 'by blocks'

    Works like a charm! You just saved me from a lot of troubles

    THANKS to both of you!

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,799

    Re: Calculating differences between cell contents 'by blocks'

    Glad you got something to work but I'm puzzled by your reference to an error message. What error? Here is my implementation using your sample data: [TF1985=series of blocks.xlsx]

  7. #7
    Registered User
    Join Date
    11-09-2012
    Location
    Berlin
    MS-Off Ver
    Excel for Mac
    Posts
    9

    Re: Calculating differences between cell contents 'by blocks'

    Ah it was just that I put it in exactly like the quote above, and there the arguments are separated by commas, as opposed to semicolons. It works perfectly of course in your sample. As I said I'm new to Excel, could have figured that out myself

    Thanks again.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,799

    Re: Calculating differences between cell contents 'by blocks'

    I see. I am using the U.S. settings and I think European settings use the semi-colon. I wrote my formula with commas in my file but when you open, I guess you see semi-colons.

  9. #9
    Registered User
    Join Date
    11-09-2012
    Location
    Berlin
    MS-Off Ver
    Excel for Mac
    Posts
    9

    Re: Calculating differences between cell contents 'by blocks'

    Ah okay, yeah that's probably the explanation - I see semicolons

+ 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