Matrix Falling Numbers Effect in Excel using VBA

I am a huge fan of the Matrix movie series. It an amazing piece of work of its time and one of my favorites science fiction movie series.

If you have seen Matrix, there is no way you wouldn’t remember the falling code sequence.

I thought of creating this in Excel, but someone beat me to it. It has already been created and is available here.

Nitin Mehta, who created this, used a couple of Excel functions, conditional formatting, and a scroll bar to create this effect.

I have modified it to remove the scroll bar and have used a VBA code instead. Now you can simply click on the play button and the numbers would start falling by itself. Something as shown below:

Matrix Falling Numbers

 Matrix Falling Numbers Effect in Excel

Here are the steps to create the matrix falling numbers effect in excel:

  • In the first row in the range A1:AP1, enter random numbers between 0 to 9. You can either manually enter these numbers of use the RANDBETWEEN function. Remember to convert these numbers into values.
    • Reduce the column width so that it is visible in a single screen.

Matrix Falling Numbers - first row

  • In the range A2:AP32, enter the formula: =INT(RAND()*10)
  • Copy and paste the below code in a module in VBA
    #If VBA7 Then
    Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 64 Bit Systems
    #Else
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
    #End If
    
    Sub MatrixNumberRain()
    i = 1
    Do While i <= 40
    DoEvents
    Range("AR1").Value = i
    i = i + 1
    Sleep 50
    Loop
    End Sub

This above code would enter the number from 1 to 4o in cell AR1. The code Sleep 50 would delay the entering of numbers by 50 milliseconds. If you run this code, you would be able to see the value in AR1 go from 1 to 40.

Now we need to specify three conditional formatting rules to give color to these numbers.

Conditional Formatting Rule #1

  • Select the range A2:AP32, go to Home –> Conditional Formatting –> New Rule

Matrix Falling Numbers - New Rule in Conditional Formatting

  • In the New Formatting Rule dialogue box, click on ‘Use a formula to determine which cells to format’ and enter the following formula:
    =MOD($AR$1,15)=MOD(ROW()+A$1,15)

Matrix Falling Numbers - Conditional Formatting formula 1

  • Click on format button and set the font color to white

Matrix Falling Numbers - Conditional Formatting color

  • Click OK

Conditional Formatting Rule #2

  • With the range A2:AP32 selected, go to Home –> Conditional Formatting –> Manage Rule
  • In the Conditional Formatting Rules Manager dialogue box, click on New Rule
  • In the New Formatting Rule dialogue box, click on ‘Use a formula to determine which cells to format’ and enter the following formula:
    =MOD($AR$1,15)=MOD(ROW()+A$1+1,15)
  • Click on format button and set the font color to light green
  • Click OK

Conditional Formatting Rule #3

  • With the range A2:AP32 selected, go to Home –> Conditional Formatting –> Manage Rule
  • In the Conditional Formatting Rules Manager dialogue box, click on New Rule
  • In the New Formatting Rule dialogue box, click on ‘Use a formula to determine which cells to format’ and enter the following formula:
    =OR(MOD($AR$1,15)=MOD(ROW()+A$1+2,15),MOD($AR$1,15)=MOD(ROW()+A$1+3,15), MOD($AR$1,15)=MOD(ROW()+A$1+4,15),MOD($AR$1,15)=MOD(ROW()+A$1+5,15))
  • Click on format button and set the font color to light green.
  • Click OK.

Based on the row number and value in the first row, conditional formatting would color the text green, light green or white.

Now select the entire range of cells (A1:AP32) and make the background black.

As a final step, insert a shape/button and assign this macro to that shape/button.

Note: Since this has a VBA code in it, save the file with .xls or .xlsm extension.

That’s it! Now get yourself a cup of coffee, stand in the shade, and enjoy the Matrix falling numbers digital rain 🙂

Download the Example File
Download File

You May Also Like the Following Excel Tutorials:

Excel Ebook Subscribe

FREE EXCEL BOOK

Get 51 Excel Tips Ebook to skyrocket your productivity and get work done faster

Sumit Bansal
Hello there! I'm Sumit Bansal, founder of trumpexcel.com and an Excel MVP. I started this website in 2013 with a simple goal: to share my love for Excel through easy to follow tips, tutorials and videos. I'm here to help you get the best out of MS Excel to save time and boost your productivity.

5 thoughts on “Matrix Falling Numbers Effect in Excel using VBA”

    • Got it:

      Public iMatrix As Boolean

      #If VBA7 Then
      ...

      Sub MatrixNumberRain()
      If iMatrix = False Then
      iMatrix = True
      i = 1
      Do While iMatrix = True
      DoEvents
      Range("AW1").Value = i
      i = i + 1
      Sleep 100
      Loop
      Else
      iMatrix = False
      End If
      End Sub

      Reply
  1. Hi Sumit, glad to see you found this app useful and good work with the macro!

    Nice site, keep up the good work!

    Best wishes,
    Nitin

    Reply

Leave a Comment

Free-Excel-Tips-EBook-Sumit-Bansal-1.png

FREE EXCEL E-BOOK

Get 51 Excel Tips Ebook to skyrocket your productivity and get work done faster

Free-Excel-Tips-EBook-Sumit-Bansal-1.png

FREE EXCEL E-BOOK

Get 51 Excel Tips Ebook to skyrocket your productivity and get work done faster

Free Excel Tips EBook Sumit Bansal

FREE EXCEL E-BOOK

Get 51 Excel Tips Ebook to skyrocket your productivity and get work done faster