Next blank row

Description

Finds the next available blank row in a worksheet. This macro allows you to get the blank at the very end of your data (not between it).

(function () 
{
    // Getting the active sheet
    var activeSheet = Api.ActiveSheet;
    // Minimum row index
    var indexRowMin = 0;
    // Maximum row index
    var indexRowMax = 1048576;
    // Column 'A'
    var indexCol = 0;
    // Row index for empty cell search
    var indexRow = indexRowMax;
    for (; indexRow >= indexRowMin; --indexRow) {
        // Getting the cell
        var range = activeSheet.GetRangeByNumber(indexRow, indexCol);
        // Checking the value
        if (range.GetValue() && indexRow !== indexRowMax) {
            range = activeSheet.GetRangeByNumber(indexRow + 1, indexCol);
            range.Select();
            break;
        }
    }
})();

Methods used: GetActiveSheet, GetRangeByNumber, Select

Reference Microsoft VBA macro code

This VBA macro was used as a base.

Sub example()
    Range("A" & Rows.Count).End(xlUp).Offset(1).Select
End Sub

Result

Next blank row

Get Help

  • If you have any questions about ONLYOFFICE Docs, try the FAQ section first.
  • You can request a feature or report a bug by posting an issue on GitHub.
  • You can also ask our developers on ONLYOFFICE forum (registration required).