How to a Create Animation in Excel VBA (Easy Steps)

Step 1 – Select Sample Items for Animation in Excel

  • In this tutorial, we’ll use a football as our sample item. When you press the “Start” button, the football will move, and it will stop when you hit the “Stop” button.
  • For demonstration purposes, let’s choose the following sample items:
    • Football
    • 3D Wall
    • Grass Ground

Animation in Excel VBA Sample Item

Read More: How to Create Animated Bar Chart Race in Excel (with Easy Steps)


Step 2 – Add Icons in Excel VBA to Create Animation

  • Firstly, go to the Insert tab.
  • Secondly, select Icons from the Illustrations group.

Select Sample Items for Animation in Excel

  • Search for Start in the search box and select the icon.
  • Press Insert.

  • Modify the button appearance and change its name to Start.

  • Similarly, add a Stop button and change its name.

  • Click on Stock 3D Models and select a football.

Select Sample Items for Animation in Excel

  • Insert it and rename it to Football.

  • Add a 3D wall and a grass ground, renaming them accordingly.

Add Icons to Create Animation in Excel VBA

Read More: How to Create 3D Animation in Excel


Step 3 – Insert VBA Code

  • Right-click the Start button and select Assign Macro.

Insert VBA Code to Create Animation in Excel

  • Choose New from the dialog box.

  • Enter the following VBA macro in the module:
Sub Start_Click()
x = 0
Do
DoEvents
x = x + 1
Sheet1.Shapes("FootBall").Left = x
Sheet1.Shapes("FootBall").Rotation = x
Loop Until x = 260 Or s
Do
DoEvents
x = x - 0.6
Sheet1.Shapes("FootBall").Left = x
Sheet1.Shapes("FootBall").Rotation = x
Loop Until x = 260
End Sub

  • Similarly, assign a macro to the Stop button.
Sub Sheet1_Stop_Click()
s = 0
End
End Sub

VBA Code to Create Animation in Excel


Final Output

  • Press the Start button, and the Football will start moving.
  • It will hit the Wall and return to its initial position.
  • The rotation will continue, and you can stop the ball by hitting the Stop button at any position.

Animation in Excel VBA


Download Practice Workbook

You can download the workbook used for the demonstration from the download link below.


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Mehedi Hasan
Mehedi Hasan

Mehedi Hasan, a BSc graduate in Naval Architecture & Engineering from Bangladesh University of Engineering and Technology, plays a pivotal role as an Excel & VBA Content Developer at ExcelDemy. Fueled by a profound passion for research and innovation, he actively engages with Excel. In his capacity, Mehedi not only adeptly tackles intricate challenges but also showcases enthusiasm and expertise in navigating tough situations with finesse, underscoring his unwavering dedication to consistently delivering exceptional and high-quality content. He... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo