Running # of days

panelman

New Member
Joined
Nov 10, 2005
Messages
10
Suppose I am running an ongoing test that involves measuring weights at some interval of days. Columns are arranged as:
Column A = date of initial weight
Column B = # of days between inital weight and weight1
Column C = weight1
Column D = # of days between initial weight and weight2
Column E = weight2
ect., etc.

As the weights are entered through the test process I would like for the number of days from start to be calculated automatically for each weight without adding any more columns or manually inputing the date each weight is taken.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi, Welcome to the board!

A worksheet change event should do the trick:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 3 And Target.Column <> 5 Then Exit Sub
If Target.Cells.Count <> 1 Then Exit Sub
If Target.Text = "" Then Exit Sub

Dim vInitDate As Variant

vInitDate = Cells(Target.Row, 1).Value
If IsDate(vInitDate) Then
    Application.EnableEvents = False
    Cells(Target.Row, Target.Column - 1).Value = Int(Date - vInitDate)
    Application.EnableEvents = True
End If

End Sub

to install, right-click the sheet tab, select 'View code' & paste above code into code window.
 
Upvote 0

Forum statistics

Threads
1,214,722
Messages
6,121,140
Members
449,012
Latest member
Lilcps

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top