ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   rotate picture based on cell value (https://www.excelbanter.com/excel-programming/439285-rotate-picture-based-cell-value.html)

elwood

rotate picture based on cell value
 
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?



Dave Peterson

rotate picture based on cell value
 
Untested...

Selection.ShapeRange.IncrementRotation activesheet.range("k9").value



elwood wrote:

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?


--

Dave Peterson

elwood[_2_]

rotate picture based on cell 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.

---
frmsrcurl: http://msgroups.net/microsoft.public...-on-cell-value

Barb Reinhardt

rotate picture based on cell value
 
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.
--
HTH,

Barb Reinhardt



"elwood" wrote:

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.

---
frmsrcurl: http://msgroups.net/microsoft.public...-on-cell-value
.


elwood[_2_]

rotate picture based on cell value
 
that's exactly what i would do, if i had the slightest idea how.... ;)

---
frmsrcurl: http://msgroups.net/microsoft.public...-on-cell-value

Dave Peterson

rotate picture based on cell value
 
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



elwood wrote:

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.

---
frmsrcurl: http://msgroups.net/microsoft.public...-on-cell-value


--

Dave Peterson

elwood[_2_]

rotate picture based on cell value
 
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....

---
frmsrcurl: http://msgroups.net/microsoft.public...-on-cell-value


All times are GMT +1. The time now is 05:10 PM.

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