Phil-
My best guess is your use of the offset statement, but here goes a longer
response just in case that isn't it.
What are your variable values just before the select statement?
Please forgive me if you already know how to find these, but if you don't
you can either set a watch on the values, set a breakpoint in code and then
mouse-over the variables to see their values, or you can put in a msgbox such
as the following right before the line that errors out:
msgbox actdate & chr(13) & rn & chr(13) & stdate
to provide the three critical values and include them in a follow-up post.
What I suspect is happening: As a general rule I'd suggest avoiding VB
commands as variable names. Instead of
offset = actdate – stdate
try using
MyOffset = ...
or something else you personalize; using VBA keywords can have unintended
and sometimes undesirable effects. In this case, on your select statement, I
suspect Excel thinks you are using the VBA command "offset" instead of your
own variable name, in which case Excel thinks your select statement (or the
offset piece of it, anyway) is missing parameters in your syntax
[offset(x,y)].
HTH,
Keith
Phil H said:
I get a run-time error 1004 on the .Select line. Can someone suggest a fix?
Sub FindDate()
Dim rn As Long, offset As Long
Dim stdate As Date, actdate As Date
actdate = Range("Z2").Value
rn = IsoWeekNumber(actdate)
If rn / 2 <> Int(rn / 2) Then rn = rn – 1
stdate = Range("A" & rn + 6).Value
offset = actdate – stdate
Range(Cells(rn + 6, 3 + offset), Cells(rn + 7, 3 + offset)).Select
End Sub