+ Reply to Thread
Results 1 to 16 of 16

VBA to Rotate image incrementally based on cell values

  1. #1
    Registered User
    Join Date
    01-21-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    8

    VBA to Rotate image incrementally based on cell values

    I'm looking for some guidance for the vba code to use that will incrementally rotate an image based on values entered within a cell of an Excel spreadsheet.

    I have two graphics, one is the face of a dial and the other is the pointer very much like a speedometer. I can achieve the desired outcome using two excel charts, one overlaid on top of the other, but, this doesn't give me the visual effect I'm looking for. please can you help.

    I'm using the face of the semicircle dial as the background image and I have a separate image for the pointer. When a value between 1 and 100 is entered in cell O3 i would like the pointer to rotate to that position on the dial. The pointer is to have a fixed position and arc left to right where the value of 1 is left-most and horizontally aligned, and for the value 100 the pointer would point in the opposite direction. Any help would be gratefully received.

    Thank you,

    Steve Gilbert

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: VBA to Rotate image incrementally based on cell values

    Checkout the coding and performance of the attached



    By changing the j-loop things can be slowed down or sped up
    Attached Files Attached Files
    Gary's Student

  3. #3
    Registered User
    Join Date
    01-21-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VBA to Rotate image incrementally based on cell values

    Jakob, thanks for taking the time to reply. I've opened the spreadsheet and can see the code behind the Developer tab but i can't get the arrow to move when the value in O3 manually changes. I'me using Excel 2010. Any thoughts?

    I've uploaded a file with the dial background and pointer.

    Best wishes,
    Steve
    Attached Files Attached Files

  4. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: VBA to Rotate image incrementally based on cell values

    As coded, you would first load a value in O3 and then manually run the macro. The arrow should then rotate.

  5. #5
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: VBA to Rotate image incrementally based on cell values

    I can get you "indicator" to rotate, but it rotates about the center of the shape rather than the "hinge"

  6. #6
    Registered User
    Join Date
    01-21-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VBA to Rotate image incrementally based on cell values

    Yes please I'd be interested in getting the indicator to work. I can then find a way to rotate it via the hinge.

    Thanks again.

    Best wishes,
    Steve

  7. #7
    Registered User
    Join Date
    01-21-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VBA to Rotate image incrementally based on cell values

    Yes please I'd be interested in getting the indicator to work. I can then find a way to rotate it via the hinge.

    Thanks again.

    Best wishes,
    Steve

  8. #8
    Registered User
    Join Date
    10-09-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: VBA to Rotate image incrementally based on cell values

    Quote Originally Posted by Jakobshavn View Post
    Checkout the coding and performance of the attached



    By changing the j-loop things can be slowed down or sped up
    I cannot make this work. Why?

  9. #9
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: VBA to Rotate image incrementally based on cell values

    Hi rintelen:

    Try this version:
    1. Enable Macros
    2. Push the Button
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    10-09-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: VBA to Rotate image incrementally based on cell values

    thanks. That worked. This is rather cool.

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: VBA to Rotate image incrementally based on cell values

    Simplest way to rotate around a point that is not the center of the shape is to group it with a larger shape and rotate the group about it's center.

    Workbook includes a UDF to rotate the shape based on a cell value. The scroll bar is linked to that value and provides an easy way to see the animation manually.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  12. #12
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: VBA to Rotate image incrementally based on cell values

    Andy:

    Thank you very much!

    This answers my post as well:

    http://www.excelforum.com/excel-prog...-rotation.html

    I will mark mine "Solved"

  13. #13
    Registered User
    Join Date
    01-21-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VBA to Rotate image incrementally based on cell values

    Andy, this is fantastic thank you very much. A quick question. . . . how would I change the scale so that the value of the dial starts at 0 and ends at 100 instead of 180?

    Best wishes,
    Steve

  14. #14
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: VBA to Rotate image incrementally based on cell values

    Change the scroll bar to have a max of 100.

    Change the udf to

    =ROTATE_SHAPE( "Sheet1","Group 11", M8*(180/100))

  15. #15
    Registered User
    Join Date
    01-21-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VBA to Rotate image incrementally based on cell values

    Andy, Absolute star. Thank you very much.

    Best wishes,
    Steve

  16. #16
    Registered User
    Join Date
    04-06-2014
    Location
    Greenville, South Carolina
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: VBA to Rotate image incrementally based on cell values

    Nicely done. Simple, direct, effective. I saw another posting on another site that had very complex trigonometry formulas and such. I'm sure they were correct but couldn't understand it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1