Formula for Date ranges


Posted by Stephen Williams on May 10, 2001 8:06 PM

Hello all,

I have a spreadsheet here at work that lists sales (dollar amounts of contracts)of systems along with their projected install dates. I would like a formula or macro that would look at these projected dates and if they were within a certain date range, to put the dollar amount in another column. In this case I have columns setup for different months, so if an installed is projected to go in on May 25th, it would put the dollar amount in the May column, June 8th, the June column, etc. Any help or ideas would be greatly appreciated.

Posted by Kevin James on May 10, 2001 8:20 PM

Hello Stephen,

I typically do not give away this stuff free, especially to a business, but the following example will be available for download until next Monday, when I remove it.

(broken link)

Kevin

Posted by Anon on May 10, 2001 9:41 PM


Using Kevin's sample data, here's another way with VBA. The slight advantage is that the worksheet formulas per Kevin's example can be elimimated and therefore do not have to be filled down as new data is entered in columns A & B. Also, the first row with the numbers 1 to 12 can be eliminated.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim col As Integer
With Target
If .Column = 1 Or .Column = 2 Then
Range(Cells(.Row, 3), Cells(.Row, 15)).ClearContents
col = Month(Cells(.Row, 1)) + 2
Cells(.Row, col).Value = Cells(.Row, 2).Value
End If
End With
End Sub

Posted by Dave Hawley on May 11, 2001 1:56 AM

Hi Stephen

Here is some code that should be placed with the Module of the Worsheet concerned. The code will run automatically each time a date is entered in the range A2:A5000.

To get to the Worsheet Module, right click on the Sheet name tab and select "View Code" then paste in the code. Then Push Alt+Q to return to Excel.


This code is set up for your date headings being in C1:N1 eg Jan Feb Mar etc.
The date to check being anywhere in A2:A5000.
The dollar amount being in B2:B5000.


Private Sub Worksheet_Change(ByVal Target As Range)
'Written by OzGrid Business Applications
'www.ozgrid.com
Dim rWatchRange As Range
Dim rDateRow As Range
Dim sMonth As String
Dim iEntryRow As Integer
Dim dDollar As Double

If Target.Cells.Count > 1 Then Exit Sub

Set rWatchRange = Range("A2:A5000")
If Intersect(Target, rWatchRange) Is Nothing Then Exit Sub

'Entry cell contains a Date and the cell to the right
'has a dollar amount.
If IsDate(Target) And IsNumeric(Target.Offset(0, 1)) Then
'Entry cell falls with the date 12/22/2000 and 22/2/2001
If Target.Value > DateSerial(2000, 12, 22) And _
Target.Value < DateSerial(2001, 2, 22) Then

'Parse text Month to String
sMonth = Format _
(DateSerial(Year(Target), _
Month(Target), Day(Target)), "mmm")
'Parse Month heading range to Range Variable
Set rDateRow = Range("C1:N1") 'Jan to Dec
'Parse Row number to Integer
iEntryRow = Target.Row
'Parse the amount to Double
dDollar = Target.Offset(0, 1).Value
'Find the date heading and offset one less than
'the entry cells row.
rDateRow.Find _
(What:=sMonth, After:=rDateRow.Cells _
(1, 1)).Offset(iEntryRow - 1, 0) = dDollar

Set rDateRow = Nothing
Set rWatchRange = Nothing

End If
End If
End Sub


This could also be set up to be run whenever a button is clicked. Then an InputBox could collect the date range to check and move all data the meets the criteria.

Dave


OzGrid Business Applications

Posted by Anon on May 11, 2001 3:00 AM


I think it advisable also to provide for the possibilities of :
- an amount in column B being changed after the date has been entered in column A, and
- a date in column A being changed from one month to another month ?



Posted by Stephen Williams on May 12, 2001 6:56 PM

Thanks to everyone for their help. I will try your suggestions.