View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
Ken Johnson
 
Posts: n/a
Default change autoshape by condition from a cell value

Hi Emil,
You must have rocks in your head;-)

after the code I try the query: ?Application.EnableEvents<
which after I hit enter returned: Print.Application.EnableEvents<


Sounds to me like you typed it in the Sheet1 code module instead of the
Immediate window. The confusion is understandable.
Control+G or ViewImmediate window will both open the Immediate window.
In the Sheet1 code module ? is just shorthand for Print, explaining the
returned result.

However, it sounds like Disabled Events is not your problem. It could
just be the code's logic. I'm very good at getting the Boolean stuff
wrong, and it sometimes takes me a few attempts to sort things out.(I'm
only a plain high school science teacher)

The code works but the referencing cell $H$19 is a result of a<
calculation (cos of another cell value).<
It works only when I select this cell (click on it). As soon as I click<
elsewhere the darn triangle flips back!<


If you want the triangle up for H19=0 and down for H19<0 then I would
say change...

If Target.Address = "$H$19" And Target = 0 Then

to...

If Range("$H$19") = 0 Then

Unless I'm mistaken, your code doesn't need to know which cell is the
target cell.


You can change a shape's name in the Name box, which is on the left
side of the Formula Bar. Just select the shape, click in the Name box,
type the new name then press enter. Two shapes on the same sheet can't
have the same name. If you select a shape, then try to give it the same
name as another shape on that sheet, then all that happens is the
original shape with that name is selected. Oddly though, if you
duplicate a shape its duplicate does have the same name, but your code
will ignore it.

When coding with shapes I like to use a meaningful name, declare the
shape as a Shape Object and Set it as an Object Variable. If your code
has to manipulate the shape a fair bit it makes your code easier to
write.

Using this code as an example, I would firstly draw then select the
triangle then type shpArrow in the Name box then press Enter.
Then I would set up the following Event Procedure..

Sub Worksheet_Change(ByVal Target As Range)
Dim shpArrow as Shape
Set shpArrow = Me.Shapes("shpArrow")
'Me is shorthand for the Sheet belonging to that code module
If Range("$H$19") = 0 Then
shpArrow.Rotation = 0
Else
shpArrow.Rotation = 180
End If
End Sub

Hope this helps.

Let me know how you go.

Ken Johnson