+ Reply to Thread
Results 1 to 17 of 17

how to subtract a set value from a cell when a another cell records a value of 1

  1. #1
    Registered User
    Join Date
    12-06-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    9

    Angry how to subtract a set value from a cell when a another cell records a value of 1

    hi all , Im new to this and i would describe myself as a novice user in excel. however im learning, and this is why im on this forum.
    I have a problem with a spreadsheet that im putting togeather, and that is , i want to subtract a set value of 7.6 from cell I4 when a value of 1 is counted in cell F10. So if cell F10 counts 2 then another value of 7.6 is subtracted from cell I4. im using a countif function in cell F10 which is counting from a dropdown list which populates cells E22:E418.
    I dont want any formula in cell I4 because this cell is required to enter values as required.
    Im assuming this can only be done with VB code so could someone please help me with this. My knowledge of VB code is below basic so could you please keep replies as simple as you can.


    thank you .

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,954

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    Hi and welcome to the forum

    Im assuming this can only be done with VB code
    You assume correctly, a cell can either contain data (text/value) or a formula, it cannot contain both
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    My first suggestion is attach a sample workbook, while you give some ideas of the cells being referenced, a sample workbook would give us a clearer picture of what YOU would like to see the results as:
    To Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

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

    View Pic
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  4. #4
    Registered User
    Join Date
    12-06-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    9

    Angry Re: how to subtract a set value from a cell when a another cell records a value of 1

    hi again, here is a copy the workbook that i am working with. i have entered the fields manually to give you an idea of what i mean.

    could you please check the formula in cells J4 and J5 and correct it so it can convert hours to days eg 7.6 hours to 1 day of leave.
    I hope i havnt confused you any more than i am at the moment .

    thanks again
    Attached Files Attached Files

  5. #5
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    I'm not sure what the problem is, unless you want to change the formula a bit :
    =INT(I4/7.6)&"-"&ROUND(MOD(I4,7.6),1)
    other than that, the formulas are displaying exactly what you are describing, Days & Parts of Days, the reason the round() works better, is that it cuts of the level of precision at 1 decimal point, your original formulas went full prcision, which probably added a little bit of (UNAVOIDABLE) roundof error at the 12th or 13th or 14th decimal, if you had expanded the row width till the '###..." had dis-appeared, you probably would have caught it your self

  6. #6
    Registered User
    Join Date
    12-06-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    Hi all, I was just wondering if anyone has had in success in constructing a VBA code for the original problem that i posted. im tearing my hair out as we speak .. grrrrrr.

    thanks ...

  7. #7
    Registered User
    Join Date
    12-06-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    Hi all, further to my original problem, another way of writing a VBA code would be to have the code subtract a value of 7.6 from cell I4 when ever a set text is selected from the drop down box located in the cells E22:E418. eg Every time "A/Leave" is selected in the drop down box 7.6 is subtracted from cell I4.

    Thanks for looking at this .

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,657

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    J4:
    Please Login or Register  to view this content.
    Last edited by protonLeah; 12-09-2013 at 02:31 AM.
    Ben Van Johnson

  9. #9
    Registered User
    Join Date
    12-06-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    thanks protonleah, but i cant have a formula in cell J4 due to the fact that i need to enter values in that cell , hence why i was looking at the VBA option. can you help me with this

    cheers.

  10. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,657

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    In post #1 you said: "... I dont want any formula in cell I4 because this cell is required to enter values as required. ...". It was my understanding that you wanted J4 to convert the hours in I to 7.6 hr days. It seems like you are asking to be able to manually put some value in J4 and have a VBA function to convert that to ??? Are you manually filling I4 or J4 and with what values?

  11. #11
    Registered User
    Join Date
    12-06-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    im entering a value into cell I4 in "hours"and its being converted into the number of "days"in cell J4 via this formula in J4 =INT(I4/7.6)&"-"&ROUND(MOD(I4,7.6),1).
    what i want to do is have the sum of 7.6 hours to be subtracted from the value in cell I4 when the text "Annual Leave"is selected from a drop down list in another cell.

    I hope this makes sense to you,
    thank you for your replies

    cheers.

  12. #12
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,657

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    The formula =ROUND((I4-F10*7.6)/7.6,1)in J4 subtracts multiples of 7.6 from the value in I4 based on the number in F10. If F10 is zero, 0 is subtracted. If F10=2, 15.2 is subtracted, etc. The remainder of the subtraction is divided by 7.6 to convert the hours to 7.6 hour days. The number, 100 in this case, remains in I4.

    An alternative:
    F10 = 3, you enter 100 in I4, and a VBA cell change is triggered which multiplies 7.6 by 3, subtracts 22.8 from 100 and puts 77.2 back in I4. THEN, the formula in J4, or the VBA, just divides 77.2 by 7.6 (10.16 days in J4) . Notice that the original 100 in I4 is lost. Is this what you are looking for?
    Do you want the original 100 in I4 replaced by VB?

  13. #13
    Registered User
    Join Date
    12-06-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    your alternative suggestion sounds just like what im trying to do, the value in I4 needs to decrease every time 7.6 is subtracted. can this be done with vb script ?
    If so could you please write it for me as i have not much knowledge of vb script

    thank you ..

  14. #14
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,657

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    Try this solution:
    This is the worksheet change event handler. It will call the actual calculation code below if you make a change in I4,
    I5 or Column E

    Please Login or Register  to view this content.
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Right click the selected sheet's tab
    4. Choose View Code
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)




    Please Login or Register  to view this content.
    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    12-06-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    thank you for your great efforts , but i just cant seem to get it working on my original spreadsheet. i have copied the codes exactly as you have sent them and i have downloaded the reformat version that you sent me and that works fine.
    You made reference to active sheet 4 and 5 in your event handler code , which i dont have sheet 4 and 5 on my spreadsheet.
    help please

    thanks again.

  16. #16
    Registered User
    Join Date
    12-06-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    here is my work diary that im working on .. could you put the code it it and test it please.

    much appriciate you efforts.
    cheers.
    Attached Files Attached Files

  17. #17
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,657

    Re: how to subtract a set value from a cell when a another cell records a value of 1

    1. In your workbook, you have an existing sheet change event handler Developed by Contextures Inc. When you copied mine in, you changed the name to Worksheet_Changes. The event handler names are part of Excel, you can't change or modify the names. So, when you made the changes Excel never saw the new procedure. Delete the s from the name and either comment out or delete the code from Contextures. You can have only one Private Sub Worksheet_Change(ByVal Target As Range) per sheet.

    2. In my Private Sub Worksheet_Change(ByVal Target As Range), the lines

    If Not Intersect(Target, Range("I4:i5")) Is Nothing Then
    Call ConvertToDays(ActiveSheet, Target.Row)

    check if the changed cell was either I4 or I5.

    If it is TRUE that the changed cell is I4 or I5, it branches the macro ConvertToDays passing it a pointer to the sheet to use, in this case "TEMPLATE", and the row on that sheet, either row 4 or row 5.

    If it is FALSE that the changed cell is I4 or I5 then it checks to see if the changed cell is in column E cells 22 to 418 (because those are the cells you had data validation in on the sample you posted). If one of those cells was changed, then it checks to see if you selected A\Leave or SICK. If you did not then the macro does nothing and exits.
    However, if A\Leave is selected,it branches the macro ConvertToDays pointing to TEMPLATE/row 4, etc.
    Last edited by protonLeah; 12-11-2013 at 01:01 AM.

+ 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] Subtract next cell from the previous cell in a column for a range of values
    By frhling in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 12-12-2012, 10:34 AM
  2. [SOLVED] If sum of cell equals a minus number, then subtract from another cell
    By misstam17 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 11-11-2012, 09:45 AM
  3. Subtract a cell from another cell if another cell equals text
    By kokeeffe1981 in forum Excel General
    Replies: 1
    Last Post: 10-22-2012, 09:52 PM
  4. Replies: 6
    Last Post: 08-06-2012, 03:09 PM
  5. How can I subtract from Duplicate Records?
    By mn_excel_91 in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 09-23-2009, 02:37 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