Return column number of the last non-blank cell in a row
To return a column number of the last non-blank cell in a single row you will need to use VBA
Example: Return column number of the last non-blank cell in a row
Sub Return_last_column_number_with_value_in_a_row()
'declare a variable
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'calculate the last column number in a row with a value
ws.Range("B7") = Cells(4, Columns.Count).End(xlToLeft).Column
ws.Range("B7") = Cells(4, Columns.Count).End(xlToLeft).Column
End Sub
OBJECTS
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
PREREQUISITES
Worksheet Name: Have a worksheet named Analysis.
Column Range: In this example we are returning the row number of the last non-blank cell in Column B.
Worksheet Name: Have a worksheet named Analysis.
Column Range: In this example we are returning the row number of the last non-blank cell in Column B.
ADJUSTABLE PARAMETERS
Row Range: Select the row from which you want to calculate the last non-blank column number by changing the row reference (4) to any column in the worksheet, that doesn't conflict with the formula.
Output Range: Select the output range by changing the cell reference ("B7") to any cell in the worksheet, that doesn't conflict with the formula.
Explanation about the formula used to return column number of the last non-blank cell in a row
EXPLANATION
EXPLANATION
This tutorial shows and explains how to return a column number of the last non-blank cell in a row using VBA.
This tutorial shows and explains how to return a column number of the last non-blank cell in a row using VBA.
RELATED TOPICS
Related Topic | Description | Related Topic and Description |
---|---|---|
Return row number of the last non-blank cell in a column | How to return a row number of the last non-blank cell in a single column you will need to use VBA |