PDA

View Full Version : how to delete the column when the shape is deleted?



maryam
04-11-2007, 02:56 AM
we have two worksheets. In the first worksheet there are some shapes and in the second worksheet there are columns related to each shape.it means if we have 10 shapes in the first worksheet, there are 10 columns of data in the second worksheet. We want the relavent column to be deleted when the user delete the shape. It means if sheet1.shapes("1").delete then sheet2.columns("A:A").delete. under which event of the worksheet should I write the codes? how to write the codes?

Bob Phillips
04-11-2007, 04:18 AM
You don't, a shape is not part of a worksheet, so it doesn't trigger worksheet events.

You will need to write your own code and fire it from a button say.

maryam
04-11-2007, 04:28 AM
So if I write it under the click event of a button then how to say if sheets("1").shapes("1").delete is done then sheets("2").columns("A:A").delete?

Bob Phillips
04-11-2007, 04:46 AM
No, you delete the selected shape from within that button click procedure, and deletre the associated columns.

Charlize
04-11-2007, 06:18 AM
If you delete column B because you delete shape2. Will column C become B and when you delete shape 3 it will actually delete the previous column D and not column C because the columns shifted to the left ?

Charlize

maryam
04-12-2007, 04:45 AM
Dear charlize that should not be a problem. Each column has a name in the first row, so I will look for the relavant name to delete, but I cant understand what does xld mean? I want the column to be deleted if the shape is deleted? how can i write the codes?

maryam
04-12-2007, 04:48 AM
Dear xld,
I dont want to have an extra button for deleting the shapes, delete button on the keybord will do, but how to delete the column?

Bob Phillips
04-12-2007, 06:06 AM
Then I think that you are up a creek so as to speak.

geekgirlau
04-16-2007, 09:24 PM
What xld is talking about is that there is no event that you can use to trigger the macro. How are you planning to let the Excel know that it's time to run the macro? Shapes do not have events - you can assign a macro to run when the click the shape, but you cannot tell it to run a macro if the shape is deleted.

maryam
04-17-2007, 06:33 AM
thank you geek for your reply. I dont know you, first time you reply me. what about assigning macros when shape is selected? I first select the shape and then delete it using delete button.

Bob Phillips
04-17-2007, 07:31 AM
You could always refdefine the delete key and point it at your code Application.OnKey "{DELETE}", "myDelete" and then check if the selection is a shape, if so delete it and underlying columns, else just delete selection.

maryam
04-17-2007, 07:32 AM
can we write sth like this:
If selection.delete then
selection.onaction=macro1
end if

maryam
04-17-2007, 07:36 AM
dear xld, user may not necessarily delete the selected shape, but we want the column to the delete if the user deletes the shape. can you explain about redifining the key pls?

maryam
04-17-2007, 07:43 AM
let me explain more. I have an object pallete with which i can put the shapes on the worksheet. then I have a macro to open a form for each shape when selected. the code is: selection.onaction=macro
there is another macro (macro1) for deleting the relavant columns if the selected shap is deleted with delete button. how to call macro1?

Bob Phillips
04-17-2007, 07:46 AM
Read my post again, I told you exactly that.