+ Reply to Thread
Results 1 to 7 of 7

Dynamic Subtraction

  1. #1
    Registered User
    Join Date
    08-04-2016
    Location
    UK
    MS-Off Ver
    2003
    Posts
    7

    Dynamic Subtraction

    Hello,

    I have a problem that I just can't get my head around. It seems so simple, but it isn't...for me.

    On (sheet 1) I have a form with drop down boxes and a button at the bottom. Pushing this button inputs all of that data into one row on (sheet 2). Every time that button is pressed, the row on (sheet 2) moves down and fills the new data above. This all works well.

    However, on (Sheet 2) the cells in columns E and F are dates. I would like to know the difference in days between these dates and show that in column J. My problem lies in that no matter what formula I use, whenever a new data row is created, the number shown in column J remains in its cell, but refers to the row that has now moved down.

    Basically, the button is pushed and a new row is entered in row 3. Column J subtracts the dates in column E from Column F ...this is fine.

    A new row is entered by the VBA and fills row 3. The original row 3 has moved down and is now in row 4. However, the figure in Column J remains in row 3 but refers to row 4 (i.e. the row that used to be in row 3)

    Is there a way to either move this cell down one, or have it refer to the same row each time and auto-fill the result? Simple things like $F$3-$E$3 don't work, they just change to $F$4-$E$4. Perhaps the VBA can be altered to fill a new row below instead of above.

    The VBA I'm using is this;


    Sub CopyInfo()
    On Error GoTo Err_Execute

    Sheet1.Range("G2").Copy
    Sheet2.Range("A3").Rows("1:1").Insert Shift:=xlDown
    Sheet1.Range("G4").Copy
    Sheet2.Range("B3").Rows("1:1").Insert Shift:=xlDown
    Sheet1.Range("I6").Copy
    Sheet2.Range("C3").Rows("1:1").Insert Shift:=xlDown
    Sheet1.Range("I8").Copy
    Sheet2.Range("D3").Rows("1:1").Insert Shift:=xlDown
    Sheet1.Range("I11").Copy
    Sheet2.Range("E3").Rows("1:1").Insert Shift:=xlDown
    Sheet1.Range("I13").Copy
    Sheet2.Range("F3").Rows("1:1").Insert Shift:=xlDown
    Sheet1.Range("I16").Copy
    Sheet2.Range("G3").Rows("1:1").Insert Shift:=xlDown
    Sheet1.Range("I17").Copy
    Sheet2.Range("H3").Rows("1:1").Insert Shift:=xlDown
    Sheet1.Range("I18").Copy
    Sheet2.Range("I3").Rows("1:1").Insert Shift:=xlDown

    Err_Execute:
    If Err.Number = 0 Then MsgBox "Data Recorded" Else _
    MsgBox Err.Description
    End Sub



    Any help will be greatly appreciated.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Dynamic Subtraction

    Bit shorter:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    08-04-2016
    Location
    UK
    MS-Off Ver
    2003
    Posts
    7

    Re: Dynamic Subtraction

    Thanks for the quick reply and the new VBA. However, the new problem is that the total sum in Column J now moves down with each new row and leaves a blank space above. Is there a way to force this to remain in place and calculate each new row?

    Thanks again.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Dynamic Subtraction

    This will leave column J alone. Not sure what you mean about calculating each row.

    Please Login or Register  to view this content.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Dynamic Subtraction

    Ah, think this is what you want:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    08-04-2016
    Location
    UK
    MS-Off Ver
    2003
    Posts
    7

    Re: Dynamic Subtraction

    You are an actual genius. Thank you very much for this. That has solved my issue perfectly.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Dynamic Subtraction

    You're welcome. Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. Range Subtraction / Matrix Subtraction - Large data set
    By excelrabbit in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-20-2015, 07:07 AM
  2. Subtraction, Dynamic tables, Dropdown, Index
    By cashflo in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-22-2015, 08:30 AM
  3. Dynamic Stock subtraction
    By daan_vb in forum Excel General
    Replies: 2
    Last Post: 11-26-2013, 06:11 AM
  4. [SOLVED] Dynamic Subtraction
    By JKK123 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-03-2013, 06:53 PM
  5. sum of subtraction every two row
    By vietdieu in forum Excel General
    Replies: 16
    Last Post: 01-22-2012, 05:07 PM
  6. Subtraction of H:MM
    By sbossio in forum Excel General
    Replies: 4
    Last Post: 06-21-2011, 06:44 PM
  7. Subtraction
    By georgei in forum Excel General
    Replies: 7
    Last Post: 11-04-2009, 10:52 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