PC Review


Reply
Thread Tools Rate Thread

Data Validation Lost After Clearing All Shapes

 
 
Shawn
Guest
Posts: n/a
 
      14th May 2009
I'm trying to delete all shapes on a sheet which works using the below code,
but a problem I'm having is that any validation list on the same sheet is
also deleted, and once delete validation lists will NOT appear on that same
sheet again even after restarting excel.

Does anyone know how to either clear all shapes but NOT validation lists, or
have any knowledge about why this occurs and why you then can't add a new
validation list (If I goto data > validation the list settings are correct
and reference the list named range - doing the same on another tab works
correctly).

For Each oShape In Sheets("Sheet1").Shapes
oShape.Delete
Next oShape
 
Reply With Quote
 
 
 
 
Tim Williams
Guest
Posts: n/a
 
      14th May 2009
You could try using the drawingobjects collection instead.
It doesn't *seem* to include the validation drop-downs.

For Each drw In Sheets("Sheet1").DrawingObjects
....
Next drw


Tim

"Shawn" <(E-Mail Removed)> wrote in message
news:6AB38A84-D2EF-4951-831A-(E-Mail Removed)...
> I'm trying to delete all shapes on a sheet which works using the below
> code,
> but a problem I'm having is that any validation list on the same sheet is
> also deleted, and once delete validation lists will NOT appear on that
> same
> sheet again even after restarting excel.
>
> Does anyone know how to either clear all shapes but NOT validation lists,
> or
> have any knowledge about why this occurs and why you then can't add a new
> validation list (If I goto data > validation the list settings are correct
> and reference the list named range - doing the same on another tab works
> correctly).
>
> For Each oShape In Sheets("Sheet1").Shapes
> oShape.Delete
> Next oShape



 
Reply With Quote
 
Shawn
Guest
Posts: n/a
 
      14th May 2009
Good suggestion, but it ended up giving me an error (Delete method of picture
class failed - possible it's not .Delete). I figured out that the following
works. Strange part is that I still can't enter validation lists on the sheet
I used the other code on unless I create a new sheet or workbook.

For Each oShape In Sheets("Sheet1").Shapes
If oShape.Type = msoPicture Then oShape.Delete
Next oShape

"Tim Williams" wrote:

> You could try using the drawingobjects collection instead.
> It doesn't *seem* to include the validation drop-downs.
>
> For Each drw In Sheets("Sheet1").DrawingObjects
> ....
> Next drw
>
>
> Tim
>
> "Shawn" <(E-Mail Removed)> wrote in message
> news:6AB38A84-D2EF-4951-831A-(E-Mail Removed)...
> > I'm trying to delete all shapes on a sheet which works using the below
> > code,
> > but a problem I'm having is that any validation list on the same sheet is
> > also deleted, and once delete validation lists will NOT appear on that
> > same
> > sheet again even after restarting excel.
> >
> > Does anyone know how to either clear all shapes but NOT validation lists,
> > or
> > have any knowledge about why this occurs and why you then can't add a new
> > validation list (If I goto data > validation the list settings are correct
> > and reference the list named range - doing the same on another tab works
> > correctly).
> >
> > For Each oShape In Sheets("Sheet1").Shapes
> > oShape.Delete
> > Next oShape

>
>
>

 
Reply With Quote
 
Eric G
Guest
Posts: n/a
 
      14th May 2009
How about:

Sub test()
Dim oshape As Shape
Dim testIt As Boolean
'
For Each oshape In Sheets("Sheet1").Shapes
On Error Resume Next ' Non drop-downs cause an error two lines down!
testIt = False
testIt = oshape.FormControlType = xlDropDown
If (Not testIt) Then oshape.Delete
Next oshape
End Sub

HTH,

Eric

"Shawn" wrote:

> I'm trying to delete all shapes on a sheet which works using the below code,
> but a problem I'm having is that any validation list on the same sheet is
> also deleted, and once delete validation lists will NOT appear on that same
> sheet again even after restarting excel.
>
> Does anyone know how to either clear all shapes but NOT validation lists, or
> have any knowledge about why this occurs and why you then can't add a new
> validation list (If I goto data > validation the list settings are correct
> and reference the list named range - doing the same on another tab works
> correctly).
>
> For Each oShape In Sheets("Sheet1").Shapes
> oShape.Delete
> Next oShape

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
custom data validation on cells with data validation values AKrobbins Microsoft Excel Worksheet Functions 2 21st Jun 2011 04:20 PM
Deleting shapes with VB deletes cell validation as well. EH? Brettjg Microsoft Excel Programming 13 23rd Mar 2009 03:18 PM
XP has lost clipboard clearing function =?Utf-8?B?b2xlcmI=?= Windows XP Print / Fax 1 7th Jan 2005 07:28 PM
When pasting data into a column with data validation I lose validation check Brad Microsoft Excel Misc 5 17th Apr 2004 01:11 PM
Excel VBA - Clearing Shapes and Cell Contents =?Utf-8?B?Umljaw==?= Microsoft Excel Programming 2 10th Apr 2004 12:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:36 AM.