View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jim Berglund[_2_] Jim Berglund[_2_] is offline
external usenet poster
 
Posts: 86
Default Inscrutable error

Thanks, but it still won't work!

I did it, declared all my variables, recompiled, and ran it again with the
same result
Jim Berglund

"RB Smissaert" wrote in message
...
Put Option Explicit at the top of the module and alter the code till it
will compile.
Then try again.

RBS

"Jim Berglund" wrote in message
news:b_qZh.147112$6m4.105298@pd7urf1no...
I'm having a problem I can't solve.

Please do the following:
In a new worksheet
Fill Column A with any value down to row 36

In column L, place dates, as follows(row# is not important):
Row L
2 10/10/1993
3
4
5
6 5/4/2005
7 3/3/1993
8
9
10 12/3/2007
11 6/23/2000
12
13
14 8/8/2007
15 4/4/2001
etc.
for 36 rows ( the first of the pairs needs to be lower than the second,
with any number of blank cells between them)

Then run this code
Sub Prorate_Dates()

Dim RowCount, RowCount2, OldRow As Integer
Dim OldDate, NewDate, DeltaDate, MyDate As Variant
'On Error Resume Next
LastRow = Cells(Rows.Count, 1).End(xlUp).Row

First = True
For RowCount = 2 To LastRow
If IsEmpty(Cells(RowCount, "A")) Then 'if last row was empty use
todays date to prorate
If IsEmpty(Cells(RowCount - 1, "L")) Then 'Use last NewDate to
prorate
OldDate = NewDate
NewDate = Now()
DeltaDate = (NewDate - OldDate) / _
(RowCount - OldRow)
'fill in prorated dates
For RowCount2 = OldRow To (RowCount - 1)

MyDate = Cells(RowCount2 - 1, "L") + _
DeltaDate
Cells(RowCount2, "L") = MyDate
Next RowCount2

End If
First = True 'Is it the first line of the series?
Else
If First = True Then

OldDate = Cells(RowCount, "L")
OldRow = RowCount
First = False
Else
If Not IsEmpty(Cells(RowCount, "L")) Then 'if the cell is empty,
go to the nect cell
NewDate = Cells(RowCount, "L") 'Otherwise select the last
date for the series
DeltaDate = (NewDate - OldDate) / (RowCount - OldRow)
'Calculate the prorated difference between first & last and divide by the
number of empty lines

For RowCount2 = (OldRow + 1) To (RowCount - 1) 'fill in
prorated dates
MyDate = Cells(RowCount2 - 1, "L") + DeltaDate
Cells(RowCount2, "L") = MyDate
Next RowCount2

OldDate = NewDate
OldRow = RowCount
End If
End If
End If

Next RowCount

End Sub

It generates an error around line 26, and I can't understand why.

Please help!

Thanks
Jim Berglund