#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Shape names

Hi

I would like to be able to delete a shape depending on the value in a cell.

ActiveSheet.Shapes("TextBox2").Delete - works.

If [A2] = 1 then I would like to delete TextBox1.
If [A2] = 2 then I would like to delete TextBox2.


This doesn't work:

ActiveSheet.Shapes("TextBox" & [A2]).Delete

or

S1 = "TextBox" & [A2]

ActiveSheet.Shapes(S1).Delete


Can somebody help me with this ?

TIA

Andrew B
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default Shape names

Hi Andrew,
Assuming the cell which performs control is A1,
In the worksheet module, have following
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A1").Value = 1 Then
TextBox1.Visible = True
Else
TextBox1.Visible = False
End If
End Sub

HTH
Carim

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Shape names

Thanks for your reply but this is not what I am after.


Carim wrote:
Hi Andrew,
Assuming the cell which performs control is A1,
In the worksheet module, have following
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A1").Value = 1 Then
TextBox1.Visible = True
Else
TextBox1.Visible = False
End If
End Sub

HTH
Carim

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default Shape names

answered too quickly ...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
i = Range("A2").Value
ActiveSheet.Shapes("TextBox" & i).Delete
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Shape names

Thanks

Carim wrote:
answered too quickly ...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
i = Range("A2").Value
ActiveSheet.Shapes("TextBox" & i).Delete
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Shape names

If you say this works:
ActiveSheet.Shapes("TextBox2").Delete

Then what you proposed originally worked fine for me as seen from the
immediate window:

? activesheet.shapes(1).Name
Textbox2
? Range("A1").Value
2
? [a1]
2
? Activesheet.Shapes("Textbox" & [A1]).Name
Textbox2
activesheet.Shapes("Textbox" & [A1]).Delete
---------------------

Textbox2 is deleted

Tested with both a Textbox from the drawing toolbar and one from the control
toolbox toolbar.

--
Regards,
Tom Ogilvy


"Andrew B" wrote in message
...
Thanks

Carim wrote:
answered too quickly ...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
i = Range("A2").Value
ActiveSheet.Shapes("TextBox" & i).Delete
End Sub



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
my curser changed from arrow shape to a cross shape???? bj New Users to Excel 1 February 5th 07 02:47 PM
Problem with Shape Names containing punctuation Peter T Excel Programming 2 March 24th 05 04:31 PM
Shape names Don Rouse Excel Programming 1 July 7th 04 12:21 AM
Deleting a shape and the cell contents the shape is in. Dave Peterson[_3_] Excel Programming 1 October 9th 03 03:36 PM
Deleting a shape and the cell contents the shape is in. Tom Ogilvy Excel Programming 0 October 9th 03 03:43 AM


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