# Math genius (sarcasm) is treading water

If you must have a preset limit, you must have something like a InsertNewBox(height) As boolean returning false when such value can’t be included as it does not fit in the limitation.

I would do a while-wend adding the height of the rows that don’t fit to TotalHeight and get a new AreaHeight until all rows fit the columns.

If I want to get a perfect AreaHeight, I then would check each column rows Height and use the biggest value to create a new AreaHeight, then draw the rows.

That way you can get something like this:

Rick, Alberto, whats different to Normans code? Can you share please?

When I execute Norman’s code usually I get 2 missing rows, one from going from column 1 to column 2 and one going from column 2 to column 3.

When I posted about While-Wend, I’m talking about wrapping your For-Next and remove Drawing, something like this:

```While columnIndex <> columns.LastRowIndex columnIndex = 0 y = 0 For i As Integer = 0 To Rows.LastRowIndex If y + Rows(i).Size.Height > AreaHeight Then columnIndex = columnIndex + 1 y = 0 End If If columnIndex <= Columns.LastRowIndex Then y = y + Rows(i).Size.Height Else TotalHeight = TotalHeight + rows(i).Size.Height End If If columnIndex > columns.LastRowIndex Then AreaHeight = TotalHeight / ColumnWidths.Count End If Next Wend```
Now you can execute your Draw code again knowing that all Rows will fit in the columns:

```y = 0 columnIndex = 0 For i As Integer = 0 To Rows.LastRowIndex If y + Rows(i).Size.Height > AreaHeight Then columnIndex = columnIndex + 1 y = 0 End If If columnIndex <= Columns.LastRowIndex Then Columns(columnIndex).Rows.AddRow(Rows(i)) y = y + Rows(i).Size.Height End If Next```

I didn’t include the code to adjust the AreaHeight to the max column height.

Also, I changed back this code:

```' Calculate areas height. AreaHeight = (TotalHeight / ColumnWidths.Count) ```
near the top your open event.