Excel Guides

'Random Width and Height Changes in Excel'

If you are working with data in Excel, you may find that you need to change the width or height of a column or row. This can be done manually by clicking on the edge of the column or row and dragging it to the desired size. However, if you need to make random width or height changes, this can be done using a macro.

To create a macro that will make random width or height changes, first open the Visual Basic Editor (VBE) by pressing Alt+F11. Then, in the VBE window, click Insert > Module. This will insert a new module into which you can enter your code.

In the new module, enter the following code:

Sub RandomWidthAndHeightChanges()

Dim i As Integer
 Dim j As Integer
 Dim k As Integer

 For i = 1 To 100

  For j = 1 To 10

   k = Int((10 - 1 + 1) * Rnd + 1)

   Columns(i).ColumnWidth = k

  Next j

 Next i

 For i = 1 To 100

  For j = 1 To 10

   k = Int((10 - 1 + 1) * Rnd + 1)

   Rows(i).RowHeight = k

  Next j

 Next i
 
End Sub

This code will randomly change the width of columns 1 through 100, and then randomly change the height of rows 1 through 100. The changes will be made in increments of 1 point.

To run this macro, press F5 or click Run > Run Sub/UserForm. If you want to stop the macro before it finishes making all of the changes, press Esc.

Move beyond 

Excel

Get started with Causal today.
Build models effortlessly, connect them directly to your data, and share them with interactive dashboards and beautiful visuals.