Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default adding a list validation to a cell

This was covered in a thread back in 1999, but the response didn't
work for me. I'm trying to add a drop-down list to a cell with valid
entries for that cell.

With Application.ActiveWorkbook.Worksheets("Items")
.Unprotect
With .Cells(1, 1).Validation
.Delete
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Formula1:="1,2,3"
.InCellDropdown = True
End With ' Validation
End With ' Worksheet

Doesn't work. I get an 'Application-defined or object-defined error -
1004' at the Add call. I realize that there are a number of ways that
the list can be specified - a Range (named or with an address) will be
the eventual way, but I've used a typed in list as a trivial example.
I can do it in the worksheet itself, but not with VBA. The worksheet
isn't protected, the cell isn't locked. I got the Delete call from
the previous thread. Modify without the Delete doesn't work either.

This is a crucial part of the project I'm working on. It's a do or
the project dies situation.

Excel 2000 9.0.6926 SP3 on Windows 2000

Any help would be greatly appreciated!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default adding a list validation to a cell

I copied and pasted your code into a new workbook. I renamed a sheet Items and
ran the code.

It worked ok for me (xl2002).

If you do the same thing, can you get it to work?

(If the worksheet were protected and I by passed the password prompt, I'd get
the 1004 error.)

Phil Sobolik wrote:

This was covered in a thread back in 1999, but the response didn't
work for me. I'm trying to add a drop-down list to a cell with valid
entries for that cell.

With Application.ActiveWorkbook.Worksheets("Items")
.Unprotect
With .Cells(1, 1).Validation
.Delete
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Formula1:="1,2,3"
.InCellDropdown = True
End With ' Validation
End With ' Worksheet

Doesn't work. I get an 'Application-defined or object-defined error -
1004' at the Add call. I realize that there are a number of ways that
the list can be specified - a Range (named or with an address) will be
the eventual way, but I've used a typed in list as a trivial example.
I can do it in the worksheet itself, but not with VBA. The worksheet
isn't protected, the cell isn't locked. I got the Delete call from
the previous thread. Modify without the Delete doesn't work either.

This is a crucial part of the project I'm working on. It's a do or
the project dies situation.

Excel 2000 9.0.6926 SP3 on Windows 2000

Any help would be greatly appreciated!


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default adding a list validation to a cell

I figured it out! You can only add validation to the worksheet that
is active. I added a .Activate right before the .Unprotect and it
worked. Thanks for your help. The clue was when I did what you did
and it worked.


Dave Peterson wrote in message ...
I copied and pasted your code into a new workbook. I renamed a sheet Items and
ran the code.

It worked ok for me (xl2002).

If you do the same thing, can you get it to work?

(If the worksheet were protected and I by passed the password prompt, I'd get
the 1004 error.)

Phil Sobolik wrote:

This was covered in a thread back in 1999, but the response didn't
work for me. I'm trying to add a drop-down list to a cell with valid
entries for that cell.

With Application.ActiveWorkbook.Worksheets("Items")
.Unprotect
With .Cells(1, 1).Validation
.Delete
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Formula1:="1,2,3"
.InCellDropdown = True
End With ' Validation
End With ' Worksheet

Doesn't work. I get an 'Application-defined or object-defined error -
1004' at the Add call. I realize that there are a number of ways that
the list can be specified - a Range (named or with an address) will be
the eventual way, but I've used a typed in list as a trivial example.
I can do it in the worksheet itself, but not with VBA. The worksheet
isn't protected, the cell isn't locked. I got the Delete call from
the previous thread. Modify without the Delete doesn't work either.

This is a crucial part of the project I'm working on. It's a do or
the project dies situation.

Excel 2000 9.0.6926 SP3 on Windows 2000

Any help would be greatly appreciated!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default adding a list validation to a cell

I tried it again with another worksheet active (not Items).

It still worked ok (xl2002, still).

But glad you got it working.



Phil Sobolik wrote:

I figured it out! You can only add validation to the worksheet that
is active. I added a .Activate right before the .Unprotect and it
worked. Thanks for your help. The clue was when I did what you did
and it worked.

Dave Peterson wrote in message ...
I copied and pasted your code into a new workbook. I renamed a sheet Items and
ran the code.

It worked ok for me (xl2002).

If you do the same thing, can you get it to work?

(If the worksheet were protected and I by passed the password prompt, I'd get
the 1004 error.)

Phil Sobolik wrote:

This was covered in a thread back in 1999, but the response didn't
work for me. I'm trying to add a drop-down list to a cell with valid
entries for that cell.

With Application.ActiveWorkbook.Worksheets("Items")
.Unprotect
With .Cells(1, 1).Validation
.Delete
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Formula1:="1,2,3"
.InCellDropdown = True
End With ' Validation
End With ' Worksheet

Doesn't work. I get an 'Application-defined or object-defined error -
1004' at the Add call. I realize that there are a number of ways that
the list can be specified - a Range (named or with an address) will be
the eventual way, but I've used a typed in list as a trivial example.
I can do it in the worksheet itself, but not with VBA. The worksheet
isn't protected, the cell isn't locked. I got the Delete call from
the previous thread. Modify without the Delete doesn't work either.

This is a crucial part of the project I'm working on. It's a do or
the project dies situation.

Excel 2000 9.0.6926 SP3 on Windows 2000

Any help would be greatly appreciated!


--

Dave Peterson

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
Adding to a data validation list Josh Craig Excel Discussion (Misc queries) 2 June 30th 09 02:59 AM
Validation List - adding new entries watermt Excel Worksheet Functions 20 March 27th 09 10:06 PM
Validation list after adding a calendar Michael B Excel Discussion (Misc queries) 0 November 13th 08 09:36 AM
Validation List -adding data and using it later POC Excel Discussion (Misc queries) 1 July 23rd 06 05:40 AM
Adding a blank in Data Validation List? Pheasant Plucker® Excel Discussion (Misc queries) 10 March 20th 06 03:06 PM


All times are GMT +1. The time now is 12:06 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"