Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default change data validation

I have data validation (allows values in a list) set in column A (except for
A1:A5). I want to change the validation list dynamically because the values
i'm interested in will change as a query is refreshed. I've tried creating a
string variable that captures the range (set myRange = Range(("AB2"),
Selection.End(xlDown))) and using that to modify the validation:

Range("A:A").Validation.Modify xlValidateList, xlValidAlertStop, , crsRange

but i get this error - "Application-defined or object-defined error".

I get the same error if i try to create myRange as a string variable, too.
The range i want to use for the validation list will change each time a
person uses the file, so i need to get this to work.

Any advice?

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default change data validation

Hi Rachael

One way is to define a named range which is dynamic. Then use that named
range as the list in your data validation.

To enter a dynamic named range: InsertNameDefine give it a name eg
"myList" and in the RefersTo box enter:
=OFFSET(Sheet2!$A$1,0,0,COUNTA(Sheet2!$A:$A),1)

This will add a named range to column A in sheet2 which will adjust to
the number of rows of data present in that column.

In your data validation you can then use =myList in the source field.

Hope this helps
Rowan

rachael wrote:
I have data validation (allows values in a list) set in column A (except for
A1:A5). I want to change the validation list dynamically because the values
i'm interested in will change as a query is refreshed. I've tried creating a
string variable that captures the range (set myRange = Range(("AB2"),
Selection.End(xlDown))) and using that to modify the validation:

Range("A:A").Validation.Modify xlValidateList, xlValidAlertStop, , crsRange

but i get this error - "Application-defined or object-defined error".

I get the same error if i try to create myRange as a string variable, too.
The range i want to use for the validation list will change each time a
person uses the file, so i need to get this to work.

Any advice?

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default change data validation

Thanks for the suggestion. I'm still having a problem, and i don't know if
it's a problem with my named range or with the code i'm trying to use to
change the validation list.

I created a named range as suggested below:
myList=OFFSET('My Sheet'!$AB$1,0,0,COUNTA('My Sheet'!$AB:$AB)-1)

I then tried to use that range in the validation code:
Range("A:A").Validation.Modify xlValidateList, xlValidAlertStop, ,
Range("[My File.xls]![My Sheet]!myList")

When i try to run the code, i get the following error:
Run-time error '1004':
Method 'Range' of object '_Global' failed

What am i doing wrong?
thanks
rachael


"Rowan" wrote:

Hi Rachael

One way is to define a named range which is dynamic. Then use that named
range as the list in your data validation.

To enter a dynamic named range: InsertNameDefine give it a name eg
"myList" and in the RefersTo box enter:
=OFFSET(Sheet2!$A$1,0,0,COUNTA(Sheet2!$A:$A),1)

This will add a named range to column A in sheet2 which will adjust to
the number of rows of data present in that column.

In your data validation you can then use =myList in the source field.

Hope this helps
Rowan

rachael wrote:
I have data validation (allows values in a list) set in column A (except for
A1:A5). I want to change the validation list dynamically because the values
i'm interested in will change as a query is refreshed. I've tried creating a
string variable that captures the range (set myRange = Range(("AB2"),
Selection.End(xlDown))) and using that to modify the validation:

Range("A:A").Validation.Modify xlValidateList, xlValidAlertStop, , crsRange

but i get this error - "Application-defined or object-defined error".

I get the same error if i try to create myRange as a string variable, too.
The range i want to use for the validation list will change each time a
person uses the file, so i need to get this to work.

Any advice?

Thanks


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default change data validation

Ok, i got it to work by entering the formula you suggest into the Data
Validation dialog box. I'd still be interested in knowing what was wrong with
my code, though!

thanks
rachael

"rachael" wrote:

Thanks for the suggestion. I'm still having a problem, and i don't know if
it's a problem with my named range or with the code i'm trying to use to
change the validation list.

I created a named range as suggested below:
myList=OFFSET('My Sheet'!$AB$1,0,0,COUNTA('My Sheet'!$AB:$AB)-1)

I then tried to use that range in the validation code:
Range("A:A").Validation.Modify xlValidateList, xlValidAlertStop, ,
Range("[My File.xls]![My Sheet]!myList")

When i try to run the code, i get the following error:
Run-time error '1004':
Method 'Range' of object '_Global' failed

What am i doing wrong?
thanks
rachael


"Rowan" wrote:

Hi Rachael

One way is to define a named range which is dynamic. Then use that named
range as the list in your data validation.

To enter a dynamic named range: InsertNameDefine give it a name eg
"myList" and in the RefersTo box enter:
=OFFSET(Sheet2!$A$1,0,0,COUNTA(Sheet2!$A:$A),1)

This will add a named range to column A in sheet2 which will adjust to
the number of rows of data present in that column.

In your data validation you can then use =myList in the source field.

Hope this helps
Rowan

rachael wrote:
I have data validation (allows values in a list) set in column A (except for
A1:A5). I want to change the validation list dynamically because the values
i'm interested in will change as a query is refreshed. I've tried creating a
string variable that captures the range (set myRange = Range(("AB2"),
Selection.End(xlDown))) and using that to modify the validation:

Range("A:A").Validation.Modify xlValidateList, xlValidAlertStop, , crsRange

but i get this error - "Application-defined or object-defined error".

I get the same error if i try to create myRange as a string variable, too.
The range i want to use for the validation list will change each time a
person uses the file, so i need to get this to work.

Any advice?

Thanks


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default change data validation

Don't refer to the range in the code. Include the string that has the
range name, e.g.:

Range("A:A").Validation.Modify xlValidateList, _
xlValidAlertStop, , "=MyList"


rachael wrote:
Ok, i got it to work by entering the formula you suggest into the Data
Validation dialog box. I'd still be interested in knowing what was wrong with
my code, though!

thanks
rachael

"rachael" wrote:


Thanks for the suggestion. I'm still having a problem, and i don't know if
it's a problem with my named range or with the code i'm trying to use to
change the validation list.

I created a named range as suggested below:
myList=OFFSET('My Sheet'!$AB$1,0,0,COUNTA('My Sheet'!$AB:$AB)-1)

I then tried to use that range in the validation code:
Range("A:A").Validation.Modify xlValidateList, xlValidAlertStop, ,
Range("[My File.xls]![My Sheet]!myList")

When i try to run the code, i get the following error:
Run-time error '1004':
Method 'Range' of object '_Global' failed

What am i doing wrong?
thanks
rachael


"Rowan" wrote:


Hi Rachael

One way is to define a named range which is dynamic. Then use that named
range as the list in your data validation.

To enter a dynamic named range: InsertNameDefine give it a name eg
"myList" and in the RefersTo box enter:
=OFFSET(Sheet2!$A$1,0,0,COUNTA(Sheet2!$A:$A), 1)

This will add a named range to column A in sheet2 which will adjust to
the number of rows of data present in that column.

In your data validation you can then use =myList in the source field.

Hope this helps
Rowan

rachael wrote:

I have data validation (allows values in a list) set in column A (except for
A1:A5). I want to change the validation list dynamically because the values
i'm interested in will change as a query is refreshed. I've tried creating a
string variable that captures the range (set myRange = Range(("AB2"),
Selection.End(xlDown))) and using that to modify the validation:

Range("A:A").Validation.Modify xlValidateList, xlValidAlertStop, , crsRange

but i get this error - "Application-defined or object-defined error".

I get the same error if i try to create myRange as a string variable, too.
The range i want to use for the validation list will change each time a
person uses the file, so i need to get this to work.

Any advice?

Thanks




--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default change data validation

Thanks - that worked!
rachael

"Debra Dalgleish" wrote:

Don't refer to the range in the code. Include the string that has the
range name, e.g.:

Range("A:A").Validation.Modify xlValidateList, _
xlValidAlertStop, , "=MyList"


rachael wrote:
Ok, i got it to work by entering the formula you suggest into the Data
Validation dialog box. I'd still be interested in knowing what was wrong with
my code, though!

thanks
rachael

"rachael" wrote:


Thanks for the suggestion. I'm still having a problem, and i don't know if
it's a problem with my named range or with the code i'm trying to use to
change the validation list.

I created a named range as suggested below:
myList=OFFSET('My Sheet'!$AB$1,0,0,COUNTA('My Sheet'!$AB:$AB)-1)

I then tried to use that range in the validation code:
Range("A:A").Validation.Modify xlValidateList, xlValidAlertStop, ,
Range("[My File.xls]![My Sheet]!myList")

When i try to run the code, i get the following error:
Run-time error '1004':
Method 'Range' of object '_Global' failed

What am i doing wrong?
thanks
rachael


"Rowan" wrote:


Hi Rachael

One way is to define a named range which is dynamic. Then use that named
range as the list in your data validation.

To enter a dynamic named range: InsertNameDefine give it a name eg
"myList" and in the RefersTo box enter:
=OFFSET(Sheet2!$A$1,0,0,COUNTA(Sheet2!$A:$A), 1)

This will add a named range to column A in sheet2 which will adjust to
the number of rows of data present in that column.

In your data validation you can then use =myList in the source field.

Hope this helps
Rowan

rachael wrote:

I have data validation (allows values in a list) set in column A (except for
A1:A5). I want to change the validation list dynamically because the values
i'm interested in will change as a query is refreshed. I've tried creating a
string variable that captures the range (set myRange = Range(("AB2"),
Selection.End(xlDown))) and using that to modify the validation:

Range("A:A").Validation.Modify xlValidateList, xlValidAlertStop, , crsRange

but i get this error - "Application-defined or object-defined error".

I get the same error if i try to create myRange as a string variable, too.
The range i want to use for the validation list will change each time a
person uses the file, so i need to get this to work.

Any advice?

Thanks




--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html


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
Can I Change Displayed Data Through Data Validation? TEK Excel Discussion (Misc queries) 2 May 15th 09 12:25 PM
change the data validation to 'any value if 'other' is selected barry j Excel Discussion (Misc queries) 0 April 30th 09 06:54 PM
How does Data Validation change with a formula change? MayClarkOriginals Excel Worksheet Functions 3 July 5th 06 04:50 AM
Add/Change Data validation list ex1302[_7_] Excel Programming 0 July 20th 05 11:08 AM
Data Validation & ControlSource & Change event Ocker Excel Programming 4 November 5th 04 03:34 AM


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

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"