Deselect two objects after all selected

C

Cutter

Hello

Each week I copy a list of data from a web page and paste it into a
Excel worksheet. The data, However, includes dozens of small graphi
objects which I don't want so I have to delete them. I do this b
Edit>Go To>Special>Objects to select all objects on the sheet but
have to deselect two objects before hitting delete. I tried recordin
a macro for this but instead of showing a way to deselect the tw
objects it listed all of the others.

Is there a VBA equivalent to holding the shift key and clicking on th
two objects to deselect them from the selection? The two objects fo
deselection are named Picture 1 and Picture 2.

Thanks for any help you might have
 
M

Myrna Larson

I don't know of any way to "deselect" something other than by selecting
something else.

I believe you need to use a loop to delete just the pictures you want. It
might look something like this:

Sub Macro1()
Dim Obj As Object
For Each Obj In ActiveSheet.DrawingObjects
Select Case Obj.Name
Case "Picture1", "Picture2"
'don't do anything
Case Else
Obj Delete
End Select
Next Obj
End Sub

PS: I used the macro recorder to get the code for selecting the objects on the
sheet. The line referred to ActiveSheet.DrawingObjects. When I put the cursor
on that word and pressed F1 to get help on the properties and methods, I got a
message about it being a hidden object, with no help available.
 
M

Myrna Larson

Oops, I see a typo. The dot is missing between Obj and Delete, i.e. it should
be

Sub Macro1()
Dim Obj As Object
For Each Obj In ActiveSheet.DrawingObjects
Select Case Obj.Name
Case "Picture1", "Picture2"
'don't do anything
Case Else
Obj.Delete '<<<< ERROR HERE IN 1ST POST
End Select
Next Obj
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top