Rotating Pie Chart using VBA

duck_hunter_82

New Member
Joined
Oct 12, 2017
Messages
2
Good Afternoon!

I found the below code in a previous string years ago and plan to use for safety recognition (similar to drawing a name from a hat). However, I know very little about VBA. Can someone please help me identify how to modify this code to have the chart rotate longer? Maybe at minimum 2 rotations before stopping?

Sub RotateWheel02()
Dim spin As Long
Dim i As Long 'loop index
Dim start As Single 'timer start

'get the rotation
Randomize
spin = Application.Ceiling(Int(360 * Rnd + 1), 10) 'multiple of 10

For i = 0 To spin Step 10

'pause for animation effect
start = Timer
Do While Timer < start + 0.1
DoEvents
Loop

'rotate shape
ActiveSheet.ChartObjects("Chart 3").Chart.Rotation = i
Next


End Sub


Thanks,
Chris
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I realized that if I change the spin value (from 360 - 1080), I get an error when the spin exceeds a full rotation.
spin = Application.Ceiling(Int(360 * Rnd + 1), 10) 'multiple of 10

When I debug, I notice that the the value for "i" is = 370. Therefore, I imagine with will not allow me to exceeds a 370 degree rotation without faulting out. Any tips on changing the value for "i" so that it can rotate a minimum of 1080 degrees?

 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top