# Creating Mondrian Art in Excel

See how my vacation to Montreal inspired me to create Mondrian style art in Excel using VBA.

### What is Mondrian Art?

Named after Piet Mondrian who was a Dutch artist.
He is known for being one of the pioneers of 20th century abstract art, as he changed his artistic direction from figurative painting to an increasingly abstract style, until he reached a point where his artistic vocabulary was reduced to simple geometric elements.

### How Did I Discover It?

In the Montreal Museum of Fine Arts gift shop I bought this book by Antonio Lapone.

My wife said “I didn’t know that you liked Mondrian art“. I had no idea what she was referring to but thankfully she clued me in. The artist Antonio Lapone uses the Mondrian style squares and color scheme throughout the book.

### Creating Mondrian Art in Excel?

I used VBA code to randomly create colored shapes. Here’s an example:

I’m not a vba pro but I learn a lot when I play around with it. The buttons on the right run the vba code.

### Creating the VBA Code

Get my Excel file (contains macros) and follow along. Here are the steps I took to create the code:

#### 1) Let’s get started

I used the macro recorder to see how to merge cells in VBA:

With Selection

.MergeCells = True

End With

The macro recorder code will always select & merge the same cells. How can I randomize the location and size of the merged cells?

I found this code:   Set MyRange = Range(Cells(5, 5), Cells(10, 10)) and realized that I could replace the hard coded numbers with random variables (random location and size).

After a lot of trial and error I ended up with this code!

Now I added variable randcolfill to randomly assign yellow, blue or red to each merged cell.

The final macro is ‘Sub Step3_AddColor()‘. I included the macro text in sheet ‘3) Add Color (FINAL)‘.

#### 5 Macros

Clicking any of the 5 objects seen below will run a macro.

• Click the Mondrian pic to add a shape (click as many times as you’d like)
• Click ‘Add Border Color‘ after you’ve created the desired number of shapes
• Click ‘Unmerge Selection‘ to unmerge whatever you select with the mouse
• Click ‘Unmerge All Cells‘ and ‘Remove Fill Color‘ to clear the canvas

### More Mondrian & Modern Art

I started exploring other artists: Wassily Kandinsky, Ilya bolotowsky, Marc Chagall, Kazimir Malevich, etc. I think Wassily Kandinsky’s art is the most interesting.

This picture was from MOMA in New York City earlier this year. I didn’t know anything about Piet Mondrian or Modern art at that point except that I thought it was kind of weird. I’m still trying to learn what it’s all about. I can understand the part about freedom to explore ideas. Not all art has to adhere to strict rules.