ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting image on worksheet and deleting.. (https://www.excelbanter.com/excel-programming/353930-selecting-image-worksheet-deleting.html)

groundhog1

Selecting image on worksheet and deleting..
 
What's wrong with this code? It won't run. I am trying to select a .bmp
image on my worksheet and delete it. I also have a command button on the
worksheet and don't want to delete that. The button is "Button 55".
Thanks,
groundhog

Sheets("Sheet1").Select
ActiveSheet.Shapes.SelectAll
ActiveSheet.Shapes("Button 55").Deselect
Selection.Delete


Jim Thomlinson[_5_]

Selecting image on worksheet and deleting..
 
Give this a try...

Sub RemovePictures()
Dim shp As Shape

For Each shp In ActiveSheet.Shapes
If shp.Name < "Button 55" Then shp.Delete
Next shp
End Sub

--
HTH...

Jim Thomlinson


"groundhog1" wrote:

What's wrong with this code? It won't run. I am trying to select a .bmp
image on my worksheet and delete it. I also have a command button on the
worksheet and don't want to delete that. The button is "Button 55".
Thanks,
groundhog

Sheets("Sheet1").Select
ActiveSheet.Shapes.SelectAll
ActiveSheet.Shapes("Button 55").Deselect
Selection.Delete



Trent Argante

Selecting image on worksheet and deleting..
 
Change "Button 55" to "Button55"; controls can't have spaces in their names.
--
Trent Argante
[DC.J(n/a)]


"Jim Thomlinson" wrote:

Give this a try...

Sub RemovePictures()
Dim shp As Shape

For Each shp In ActiveSheet.Shapes
If shp.Name < "Button 55" Then shp.Delete
Next shp
End Sub

--
HTH...

Jim Thomlinson


"groundhog1" wrote:

What's wrong with this code? It won't run. I am trying to select a .bmp
image on my worksheet and delete it. I also have a command button on the
worksheet and don't want to delete that. The button is "Button 55".
Thanks,
groundhog

Sheets("Sheet1").Select
ActiveSheet.Shapes.SelectAll
ActiveSheet.Shapes("Button 55").Deselect
Selection.Delete



Jim Thomlinson[_5_]

Selecting image on worksheet and deleting..
 
Buttons from the forms toolbar do have spaces in them by default when they
are added. Buttons from the control toolbox don't, but you can add them in if
you wish...

Named ranges can not have spaces in them, but objects such as shapes can.

The code that groundhog first posted will crach if Button 55 does not exist,
which is why I choose the route that I did. With the posted code, if button
55 does not exist then it will just delete all of the shapes...
--
HTH...

Jim Thomlinson


"Trent Argante" wrote:

Change "Button 55" to "Button55"; controls can't have spaces in their names.
--
Trent Argante
[DC.J(n/a)]


"Jim Thomlinson" wrote:

Give this a try...

Sub RemovePictures()
Dim shp As Shape

For Each shp In ActiveSheet.Shapes
If shp.Name < "Button 55" Then shp.Delete
Next shp
End Sub

--
HTH...

Jim Thomlinson


"groundhog1" wrote:

What's wrong with this code? It won't run. I am trying to select a .bmp
image on my worksheet and delete it. I also have a command button on the
worksheet and don't want to delete that. The button is "Button 55".
Thanks,
groundhog

Sheets("Sheet1").Select
ActiveSheet.Shapes.SelectAll
ActiveSheet.Shapes("Button 55").Deselect
Selection.Delete



Jim Thomlinson[_5_]

Selecting image on worksheet and deleting..
 
The one thing I neglected to mention (probably what you are describing) in
the properties for the command button from the control toolbox the "Name" can
not have any spaces in it. In the drop down where you see the current cell
address you can add the space. Why you ever would is a complete mystery but
you can if that is what floats your boat.
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

Buttons from the forms toolbar do have spaces in them by default when they
are added. Buttons from the control toolbox don't, but you can add them in if
you wish...

Named ranges can not have spaces in them, but objects such as shapes can.

The code that groundhog first posted will crach if Button 55 does not exist,
which is why I choose the route that I did. With the posted code, if button
55 does not exist then it will just delete all of the shapes...
--
HTH...

Jim Thomlinson


"Trent Argante" wrote:

Change "Button 55" to "Button55"; controls can't have spaces in their names.
--
Trent Argante
[DC.J(n/a)]


"Jim Thomlinson" wrote:

Give this a try...

Sub RemovePictures()
Dim shp As Shape

For Each shp In ActiveSheet.Shapes
If shp.Name < "Button 55" Then shp.Delete
Next shp
End Sub

--
HTH...

Jim Thomlinson


"groundhog1" wrote:

What's wrong with this code? It won't run. I am trying to select a .bmp
image on my worksheet and delete it. I also have a command button on the
worksheet and don't want to delete that. The button is "Button 55".
Thanks,
groundhog

Sheets("Sheet1").Select
ActiveSheet.Shapes.SelectAll
ActiveSheet.Shapes("Button 55").Deselect
Selection.Delete



Trent Argante

Selecting image on worksheet and deleting..
 
I modified your code to print the names of each shape and found out what
you're talking about, and if that's not cunfusing, I don't know what is! It
seems like Excel treats shapes like ranges...
The route you took is the cleanest.
Thanks for the extended explanation - it helped me at least.
--
Trent Argante
[DC.J(n/a)]


"Jim Thomlinson" wrote:

The one thing I neglected to mention (probably what you are describing) in
the properties for the command button from the control toolbox the "Name" can
not have any spaces in it. In the drop down where you see the current cell
address you can add the space. Why you ever would is a complete mystery but
you can if that is what floats your boat.
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

Buttons from the forms toolbar do have spaces in them by default when they
are added. Buttons from the control toolbox don't, but you can add them in if
you wish...

Named ranges can not have spaces in them, but objects such as shapes can.

The code that groundhog first posted will crach if Button 55 does not exist,
which is why I choose the route that I did. With the posted code, if button
55 does not exist then it will just delete all of the shapes...
--
HTH...

Jim Thomlinson


"Trent Argante" wrote:

Change "Button 55" to "Button55"; controls can't have spaces in their names.
--
Trent Argante
[DC.J(n/a)]


"Jim Thomlinson" wrote:

Give this a try...

Sub RemovePictures()
Dim shp As Shape

For Each shp In ActiveSheet.Shapes
If shp.Name < "Button 55" Then shp.Delete
Next shp
End Sub

--
HTH...

Jim Thomlinson


"groundhog1" wrote:

What's wrong with this code? It won't run. I am trying to select a .bmp
image on my worksheet and delete it. I also have a command button on the
worksheet and don't want to delete that. The button is "Button 55".
Thanks,
groundhog

Sheets("Sheet1").Select
ActiveSheet.Shapes.SelectAll
ActiveSheet.Shapes("Button 55").Deselect
Selection.Delete



groundhog1

Selecting image on worksheet and deleting..
 
Thanks very much Jim,
that worked very well.
groundhog


groundhog1

Selecting image on worksheet and deleting..
 
Thanks very much Jim,
that worked very well.
groundhog



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com