Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default how to cast a Range value to a Date value?

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default how to cast a Range value to a Date value?

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default how to cast a Range value to a Date value?

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






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default how to cast a Range value to a Date value?

Hi Mark,

If the Cells property is not explicitly qualified, it will be implicitly
qualified to refer to the active sheet (unless the code is in a sheet
module, in which case the qualification will be to the sheet holding the
code).

Try, therefore, something like:

Dim SH As Worksheet

Set SH = ActiveWorkbook.Sheets(ShName)

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

where ShName is the passed sheet name.


---
Regards,
Norman



"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


  #5   Report Post  
Posted to microsoft.public.excel.programming
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







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default how to cast a Range value to a Date value?

the suggested qualification did the job!

As a C/C++ programmer I'm a beginner here.
I believed my code is in the WorkBook module,
not any more ...

Where it supposed to be, what is the right place for
it or what is the best place for it.
How to check where is my code?

Thanks for all your help,
deeply indebted
/mark


Norman Jones wrote:

Hi Mark,

If the Cells property is not explicitly qualified, it will be implicitly
qualified to refer to the active sheet (unless the code is in a sheet
module, in which case the qualification will be to the sheet holding the
code).

Try, therefore, something like:

Dim SH As Worksheet

Set SH = ActiveWorkbook.Sheets(ShName)

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

where ShName is the passed sheet name.


---
Regards,
Norman



"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





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default how to cast a Range value to a Date value?

Hi Mark,

I would refer you to Chip Pearson's comprehensive treatment of this precise
issue at:

http://www.cpearson.com/excel/codemods.htm


---
Regards,
Norman



"Mark Dvorkin" wrote in message
...
the suggested qualification did the job!

As a C/C++ programmer I'm a beginner here.
I believed my code is in the WorkBook module,
not any more ...

Where it supposed to be, what is the right place for
it or what is the best place for it. How to check where is my code?

Thanks for all your help,
deeply indebted
/mark




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default how to cast a Range value to a Date value?

Man!

you have answers for everything and right on the button ...

Chip Pearson's site is great.
Thanks again, I'm all set for the rest of the night.
/mark.

Norman Jones wrote:

Hi Mark,

I would refer you to Chip Pearson's comprehensive treatment of this precise
issue at:

http://www.cpearson.com/excel/codemods.htm


---
Regards,
Norman



"Mark Dvorkin" wrote in message
...


the suggested qualification did the job!

As a C/C++ programmer I'm a beginner here.
I believed my code is in the WorkBook module,
not any more ...

Where it supposed to be, what is the right place for
it or what is the best place for it. How to check where is my code?

Thanks for all your help,
deeply indebted
/mark










Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to cast com object (interop) yh Excel Discussion (Misc queries) 0 April 26th 10 09:16 AM
How do I cast time when the total exceeds 24 hours arm266 Excel Discussion (Misc queries) 11 September 26th 09 06:58 PM
CAST Function Matt S Excel Discussion (Misc queries) 1 February 19th 08 05:16 PM
Help with MSQuery & CAST function Neil Evans-Mudie Excel Programming 3 October 4th 05 05:20 PM
Need to cast OleObject to CombBbox Liline Excel Programming 1 August 29th 03 03:32 PM


All times are GMT +1. The time now is 08:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"