Create a grid of rectangles
Problem
Sometimes it's very handy to be able to create an accurately laid out grid of rectangles, for example when you want to lay out a grid so that you can do a scale drawing.
Creating a grid by hand can be tedious, boring and above all, slow. A bit of VBA makes it quick, simple and accurate.
Solution
Draw a rectangle or square covering the area you want to fill with a grid. Run this macro and it'll ask how many columns and rows of rectangles you want to fill the area with.
Sub GridInRectangle() Dim oSh As Shape Dim oSld As Slide Dim sngwidth As Single ' width/height of a grid rect Dim sngheight As Single Dim lCols As Long Dim lRows As Long Dim x As Long ' which col across are we making Dim y As Long ' which row down are we making Dim sngLeft As Single ' where to draw current rectangle Dim sngTop As Single Dim sTemp As String If Not ActiveWindow.Selection.Type = ppSelectionShapes Then MsgBox "Select something, then try again" Exit Sub End If ' get rows/cols from user sTemp = InputBox("How many columns?", "Columns") If CLng(sTemp) > 0 Then lCols = CLng(sTemp) sTemp = InputBox("How many rows?", "Rows") If CLng(sTemp) > 0 Then lRows = CLng(sTemp) Else Exit Sub End If Else Exit Sub End If Set oSh = ActiveWindow.Selection.ShapeRange(1) Set oSld = oSh.Parent sngwidth = oSh.width / lCols sngheight = oSh.height / lRows For x = 0 To lCols - 1 For y = 0 To lRows - 1 ' with osld.Shapes.AddShape(msoShapeRectangle, left, top, width, height) With oSld.Shapes.AddShape(msoShapeRectangle, oSh.Left + x * sngwidth, oSh.Top + y * sngheight, sngwidth, sngheight) Call .Tags.Add("Grid", "YES") End With Next Next End Sub
See How do I use VBA code in PowerPoint? to learn how to use this example code.