View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default how to cast a Range value to a Date value?

Public Function MyFunction(shName as String, DueDateColumn as Long)
Dim DueDateR as Range
Dim DueDate as Date
Set DueDateR = Worksheets(shName).Cells( _
Rows.Count, DueDateColumn).End(xlUp)
DueDate = DueDateR.Value

--
Regards,
Tom Ogilvy



"Mark Dvorkin" wrote in message
...
Norman,
first of all: thanks for your patience!

the call

DueDate = Cells(Rows.Count, DueDateColumn).End(xlUp).Value
is within a function which knows which sheet is active, i.e. I'm passing in
the sheet name to it. For some reason at this line my function blows up.

If I declare

Dim DueDateR as Range
and

Set DueDateR = Cells(Rows.Count, DueDateColumn).End(xlUp)


the value I find in the DueDateR is the name of the last Sheet in that
Workbook! Do I need (and if so then how)
to explicitly tell the Cells method which Sheet it has to act upon?

Thanks a lot,
/mark

Norman Jones wrote:

Hi Mark,

Try:

DueDate = Cells(Rows.Count, DueDateColumn).End(xlUp).Value


---
Regards,
Norman



"Mark Dvorkin" wrote in message
...
The right hand side of the expression below returns a Range that in my
case will always be the value of the last cell in the column DueDateColumn
.....
Dim DueDate as Date

Set DueDate = Cells(Rows.Count, DueDateColumn).End(xlUp)
.....

How can I stuff this value into the DueDate variable???????

I appreciate your patience with me and
thanks for you help in advance,
/mark