rotate picture based on cell value

  • Thread starter Thread starter elwood
  • Start date Start date
E

elwood

I have a picture (a compass arrow). I am trying to write a macro that will
rotate the image based on a value contained in a cell. Lets say the azimuth
is 87 degrees, then cell K9 would contain the value 87. I would like the
arrow to rotate by 87 deg, to visually reflect the azimuth.

So fare I am able to get the shape to rotate by a fixed value by using for
example

Selection.ShapeRange.IncrementRotation 87#

How do I have excel pick the value in cell K9 and rotate the object
accordingly?
 
Untested...

Selection.ShapeRange.IncrementRotation activesheet.range("k9").value
 
great thanks - is there a function for absolute rotation? Lets say the image sits a 87 to start with and I want to rotate it back to 0 - Currently if i enter 0, obviously nothing happens, since the rotation is relative.
 
I'd suggest you putting something in the Worksheet_SelectionChange procedure
to capture the value in the range of interest BEFORE you change it. Once
it's changed, you can recalculate the angle and set it. You will probably
need a public variable to do this.
 
You very rarely need to select an object to work with it. By not selecting the
object, it should make the code easier to read, too.

Option Explicit
Sub testme()

Dim myShape As Shape

Set myShape = ActiveSheet.Shapes("Picture 1")

myShape.IncrementRotation 45

MsgBox "Hey, it's crooked!"

myShape.Rotation = 0

MsgBox "Back to normal!"

End Sub
 
thanks again - makes a lot of sense. I have to admit, I know nothing about VB, so I just used the first example i could find that I half way understood and got to work....
 
Back
Top