Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-11-2011, 03:09 AM
tinfanide tinfanide is offline Date Subtraction Windows XP Date Subtraction Office 2010 32bit
Expert
Date Subtraction
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default Date Subtraction

A1 = formula

A2:(infinite) Date

I want starting from A2 when I type in a date, the newest substrates the oldest. When a date is added, it becomes the newest date.

I know A3-A2 can return the sum of days but in this case it involves the use of table in 2010. If I do the subtraction, when I add a new date at the bottom of the table, the date is not counted.



Is there any way to make it done?
Reply With Quote
  #2  
Old 08-15-2011, 01:30 AM
OTPM OTPM is offline Date Subtraction Windows 7 32bit Date Subtraction Office 2010 32bit
Expert
 
Join Date: Apr 2011
Location: West Midlands
Posts: 981
OTPM is on a distinguished road
Default

Hi
Can you post a sample of your spreadsheet and I can take a look for you.
Tony (OTPM)
Reply With Quote
  #3  
Old 08-16-2011, 03:13 AM
tinfanide tinfanide is offline Date Subtraction Windows XP Date Subtraction Office 2010 32bit
Expert
Date Subtraction
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Quote:
Originally Posted by OTPM View Post
Hi
Can you post a sample of your spreadsheet and I can take a look for you.
Tony (OTPM)
Like the last question I got help from you:
https://www.msofficeforums.com/excel...me-column.html
Reply With Quote
  #4  
Old 08-16-2011, 04:25 AM
Catalin.B Catalin.B is offline Date Subtraction Windows Vista Date Subtraction Office 2007
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

paste these macros in a module (change worksheet name as needed.)

Sub auto_open()
' works when you double click a cell and press enter, not when formula result changes, or when you copy formula to range
' whenever you need to update , double click on any cell then press enter
ThisWorkbook.Worksheets("Foaie2").OnEntry = "datesubs"

End Sub

Sub datesubs()
Dim lastrow As Long

With Sheets("Foaie2")
lastrow = Range("A" & Rows.Count).End(xlUp).Row
Cells(1, 1).Value = Cells(lastrow, 1).Value - Cells(2, 1).Value

End With
End Sub
Reply With Quote
  #5  
Old 08-16-2011, 05:04 AM
tinfanide tinfanide is offline Date Subtraction Windows XP Date Subtraction Office 2010 32bit
Expert
Date Subtraction
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

http://www.youtube.com/watch?v=kv2WX3KB0Z0

More on my question:
if you cannot understand my text description, please watch this video.

Last edited by tinfanide; 08-16-2011 at 05:05 AM. Reason: Fix the youtube embedded link
Reply With Quote
  #6  
Old 08-16-2011, 05:07 AM
Catalin.B Catalin.B is offline Date Subtraction Windows Vista Date Subtraction Office 2007
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

there is no video..
Reply With Quote
  #7  
Old 08-16-2011, 05:31 AM
Catalin.B Catalin.B is offline Date Subtraction Windows Vista Date Subtraction Office 2007
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

sorry, there is .. but even the name of the video says something else than your original post does (How to subtract dates from cell to cell in a table in Excel 2010)
Please save my time and try to be more explicit...
Reply With Quote
  #8  
Old 08-16-2011, 05:34 AM
tinfanide tinfanide is offline Date Subtraction Windows XP Date Subtraction Office 2010 32bit
Expert
Date Subtraction
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Yeah... sorry... my last post was misleading...
But thanks for your macros.
I'm looking deep at it now and try to figure out this.
Reply With Quote
  #9  
Old 08-16-2011, 05:39 AM
Catalin.B Catalin.B is offline Date Subtraction Windows Vista Date Subtraction Office 2007
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

ok, look at this line, which does all the job:
Cells(1, 1).Value = Cells(lastrow, 1).Value - Cells(2, 1).Value
maybe you can use this instead :
Cells(1, 1).Value = Cells(lastrow, 1).Value - Cells(lastrow-1, 1).Value
it subtracts the last value from the previous...
Reply With Quote
  #10  
Old 08-16-2011, 06:20 AM
tinfanide tinfanide is offline Date Subtraction Windows XP Date Subtraction Office 2010 32bit
Expert
Date Subtraction
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

I can get the number of days when I click run the macro datesubs, not auto_open.
When I click auto_open, nothing happens.

But when I run those two macros, I double click any cells and press "enter". It shows the error message:

"Cannot run the macro [my xlsm file location]. The macro may not be available in this workbook or all macros may be disabled."
Reply With Quote
  #11  
Old 08-16-2011, 08:10 AM
Catalin.B Catalin.B is offline Date Subtraction Windows Vista Date Subtraction Office 2007
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

here is a sample attached...
Make sure you have macro security set to "disable all macros, with notification"
and when you open this workbook, in the message bar click options-enable this macro
Attached Files
File Type: xlsm test.xlsm (17.1 KB, 12 views)
Reply With Quote
  #12  
Old 08-18-2011, 06:33 AM
tinfanide tinfanide is offline Date Subtraction Windows XP Date Subtraction Office 2010 32bit
Expert
Date Subtraction
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Quote:
Originally Posted by Catalin.B View Post
here is a sample attached...
Make sure you have macro security set to "disable all macros, with notification"
and when you open this workbook, in the message bar click options-enable this macro
Yes, thank you very much for ya file.
The only thing that goes wrong is that when I expand the table (I set the A column a table) but for whatever reasons I didn't enter a new date. So the lastrow is empty, Excel asks me to debug the line:

Code:
Cells(1, 1).Value = Cells(lastrow, 1).Value - Cells(2, 1).Value
Reply With Quote
  #13  
Old 08-18-2011, 07:56 AM
Catalin.B Catalin.B is offline Date Subtraction Windows Vista Date Subtraction Office 2007
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

can you attach a sample of your worksheet?
Reply With Quote
  #14  
Old 08-18-2011, 08:32 AM
tinfanide tinfanide is offline Date Subtraction Windows XP Date Subtraction Office 2010 32bit
Expert
Date Subtraction
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Quote:
Originally Posted by Catalin.B View Post
can you attach a sample of your worksheet?
My Fiance.xlsm

The sample data is just meaningless, nothing personal.
The error occurs when
Ya leave the last row blank and double click any cell and press ENTER.
Reply With Quote
  #15  
Old 08-18-2011, 09:12 AM
Catalin.B Catalin.B is offline Date Subtraction Windows Vista Date Subtraction Office 2007
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

maybe i am missing something, the macro works ...and is searching for the last row in column A which is not empty and subtracts it from the cell A2.
use an macro error handler in your macro: (you may copy on your code the red line)
this error handler just ignores errors, but if there are still problems, we will use another one, if necessary...


Sub datesubs()
Dim lastrow As Long
Please keep in mind that the code works only when you enter data in any cell in this worksheet, not when you copy cells or expanding tables

With Sheets("Sheet1")
On Error Resume Next
lastrow = Range("A" & Rows.Count).End(xlUp).Row
Cells(2, 1).Value = Cells(lastrow, 1).Value - Cells(4, 1).Value

End With
End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Date formatting kjxavier Excel 0 08-10-2011 08:17 AM
Date Subtraction Need a date formula MPAVLAS Excel 3 08-12-2010 10:04 PM
Date Subtraction Julian Date windseaker Excel 1 02-14-2010 01:44 AM
new appointment date always reverts back to today's date msills Outlook 0 08-24-2007 08:57 AM
Date Subtraction Imported message date change to today's date promark Outlook 1 12-23-2005 07:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:00 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft