+ Reply to Thread
Results 1 to 18 of 18

Subtract values from cells relative to ActiveCell

  1. #1
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Subtract values from cells relative to ActiveCell

    Hi.

    Go stuck on this, what I thought was simple to do, but how can I subtract between two value relative to the active cell?
    Let's say i'm in B2 I want to put the value from A2-A1.

    I tried this but get some sort of Error 13 "Incompatible types" (bad translation??)

    Please Login or Register  to view this content.
    Hope you understand what I want here.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Subtract values from cells relative to ActiveCell

    Do either A2 or A1 contain text or error values?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Subtract values from cells relative to ActiveCell

    Quote Originally Posted by Norie View Post
    Do either A2 or A1 contain text or error values?
    nope, timestamps with milliseconds.
    Like:
    A1: 14:26:24,605
    A2: 14:26:25,637

  4. #4
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Subtract values from cells relative to ActiveCell

    It works well if i just in cell B2 write function: =A2-A1 it subtract as I want to.
    But I don't want the formula in the cell just the actual value: 00:00:01,032
    Last edited by Rob*; 04-23-2013 at 09:16 AM.

  5. #5
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Subtract values from cells relative to ActiveCell

    I'd guess the problem is to do with variable types, you could try setting variables as date types and then assigning the values in the cells to the variables and doing the subtraction. I haven't being able to get this to work exactly right though. Probably the easiest thing is to write the function in the cell and then copy and pastespecial as a value.

  6. #6
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Subtract values from cells relative to ActiveCell

    I tried
    Please Login or Register  to view this content.
    And variants of:
    Please Login or Register  to view this content.
    without any success.

    Was also thinking about the PasteSpecial as a workaround.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Subtract values from cells relative to ActiveCell

    The only way I can cause a type mismatch is if there is text or an error in either or both cells.

    Works fine with the values you posted too, as long as the worksheet they are on is active and the ActiveCell is B2.

    Actually, why are you using ActiveCell?

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Subtract values from cells relative to ActiveCell

    http://www.excelforum.com/excel-new-...llisecond.html

    That seems to be the same problem - you could try the solution there but to be honest I would stick with the pastespecial.

  9. #9
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Subtract values from cells relative to ActiveCell

    Quote Originally Posted by Norie View Post
    Actually, why are you using ActiveCell?
    Don't know. Mostly, I think because it's where I end up after finding first empty row.
    And second because I don't know what else to use?

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Subtract values from cells relative to ActiveCell

    Rob

    Can you check if the times are being recognised?

    You can do that with a formula like this.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This will return TRUE if Excel is recognising the values as time, FALSE otherwise.

  11. #11
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Subtract values from cells relative to ActiveCell

    Quote Originally Posted by Norie View Post
    Rob

    Can you check if the times are being recognised?

    You can do that with a formula like this.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This will return TRUE if Excel is recognising the values as time, FALSE otherwise.
    It return: "FALSE"

    Is there any solution for that?

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Subtract values from cells relative to ActiveCell

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  13. #13
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Subtract values from cells relative to ActiveCell

    So I'm working on a lap timer thingie.
    So whenever the one i'm tracking passes the finish line I just hit Lap button.
    That way I can log the lap times.

    I attached my solution.

    The workaround from my original question with PasteSpecial is included and I just set text color to white in column A and B to hide it.
    Attached Files Attached Files

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Subtract values from cells relative to ActiveCell

    This will return a string.
    Please Login or Register  to view this content.
    The rest of the code is pretty confusing with all the selecting, offsettin etc, in fact it's making me dizzy trying to figure out what's happening.

    What, in words, should the code do?

    You mention lap times, but surely you would need a start time for that.

    I changed the code to this and changed the declaration of LapTime to Double.
    Please Login or Register  to view this content.
    That part appears to work to some extent

  15. #15
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Subtract values from cells relative to ActiveCell

    I know the code ain't too clean!
    All and all the code should just make timestamps and calculate the time between to set that as a lap time. Each new lap overmost, e.g. in C3. And also name that lap.

    I have a start time:
    As you hit the Lap-button first time you see the text "Complete Lap 1" in order to wait for the first lap to be completed, then just to hit the Lap-button. After that it's just to hit Lap-button every lap around for new times.
    I will look at the code you posted here Norie, thanks for the time, helping me out here.

  16. #16
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Subtract values from cells relative to ActiveCell

    Quote Originally Posted by Norie View Post
    I changed the code to this and changed the declaration of LapTime to Double.
    What does this do? I'm a bit confused to all these declarations...

  17. #17
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    In Excel times are numeric, you had declared LapTime as a String.

  18. #18
    Registered User
    Join Date
    09-14-2011
    Location
    Sweden
    MS-Off Ver
    Excel 2007
    Posts
    64

    Re: Subtract values from cells relative to ActiveCell

    Quote Originally Posted by Norie View Post
    In Excel times are numeric, you had declared LapTime as a String.
    Yeah, I googled it and found info about different declarations. To be honest, I found the timestamp code somewhere else and modified it to suit me. I didn't even look at the declarations.
    Thanks for all your help!

+ 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