Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Finding first value in named range referred to in data validation list

I have a cell that uses data validation (list) which points at a named range
that represents a range on a different worksheet.

I need to be able to reset the cell value to the first value on the named
range list. Here is my sample code, which isn't working:

S = Sheet12.Range("E2").Validation.Formula1
Sheet12.Range("E2").Value = Range(S)(1)

debug.print Sheet12.Range("E2").Validation.Formula1
results in the named range
=DatesForSelection14days

when I use the immediate window to set:
S = Sheet12.Range("E2").Validation.Formula1
then
debug.print Range(S)(1) I get
10/3/2008
which is correct.

But when the two lines of code run within the sub itself, on the second line
I get a run-time error 1004, method 'Range' of object '_worksheet' failed
huh?

Any advice greatly appreciated.
Thanks,
Keith


  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Finding first value in named range referred to in data validation

Probably due to S being "=DatesForSelection14days". I think you need to drop
the "=" sign


s = Sheet12.Range("E2").Validation.Formula1
s = Mid$(s, 2, Len(s))
Sheet12.Range("E2").Value = Range(s)(1)


"ker_01" wrote:

I have a cell that uses data validation (list) which points at a named range
that represents a range on a different worksheet.

I need to be able to reset the cell value to the first value on the named
range list. Here is my sample code, which isn't working:

S = Sheet12.Range("E2").Validation.Formula1
Sheet12.Range("E2").Value = Range(S)(1)

debug.print Sheet12.Range("E2").Validation.Formula1
results in the named range
=DatesForSelection14days

when I use the immediate window to set:
S = Sheet12.Range("E2").Validation.Formula1
then
debug.print Range(S)(1) I get
10/3/2008
which is correct.

But when the two lines of code run within the sub itself, on the second line
I get a run-time error 1004, method 'Range' of object '_worksheet' failed
huh?

Any advice greatly appreciated.
Thanks,
Keith



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 434
Default Finding first value in named range referred to in data validation list

hi, Keith !

I could not reproduce the error you are getting -?-

this is working just fine (for me):

With Sheet12.Range("e2")
.Value = Range(.Validation.Formula1)(1)
End With

maybe some crossed/missed/... references to libraries in your vba projet ?

hth,
hector.

__ OP __
I have a cell that uses data validation (list) which points at a named range that represents a range on a different worksheet.

I need to be able to reset the cell value to the first value on the named range list.
Here is my sample code, which isn't working:

S = Sheet12.Range("E2").Validation.Formula1
Sheet12.Range("E2").Value = Range(S)(1)

debug.print Sheet12.Range("E2").Validation.Formula1
results in the named range
=DatesForSelection14days

when I use the immediate window to set:
S = Sheet12.Range("E2").Validation.Formula1
then
debug.print Range(S)(1) I get
10/3/2008
which is correct.

But when the two lines of code run within the sub itself, on the second line
I get a run-time error 1004, method 'Range' of object '_worksheet' failed huh?

Any advice greatly appreciated.
Thanks,
Keith



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
Data Validation List from a Dynamic Named Range on Another Workshe Jeremy Excel Worksheet Functions 5 March 29th 10 09:26 AM
Dynamic Named Range inside a Data Validation list ? Richard[_34_] Excel Programming 5 March 11th 06 01:58 PM
Cell value as named range for validation list [email protected] Excel Programming 2 December 10th 05 11:05 PM
Using a data validation list to look up a defined named range in another worksheet Laura Hunt Charts and Charting in Excel 0 November 24th 05 02:29 PM
named range, data validation: list non-selected items, and new added items KR Excel Discussion (Misc queries) 1 June 24th 05 05:21 AM


All times are GMT +1. The time now is 08:42 PM.

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

About Us

"It's about Microsoft Excel"