how to Find Last non-blank Row and Column Using VBA?
Tags: tofindlastnonblankro, vbamacros
Published: 2021-09-13 05:48:41

---
title: how to Find Last non-blank Row and Column Using VBA?
published: true
date: 2021-09-09 16:38:17 UTC
tags: ToFindLastNonBlankRo,VBAMacros
canonical_url: https://geekexcel.com/how-to-find-last-non-blank-row-and-column-using-vba/
---

In this tutorial, we will guide you on  **how to find the last Non-Blank row and column using VBA**. Let’s get them below!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Find Last Non-Blank Row in a Column using Range.End

- Firstly, in the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Sub getLastUsedRow()

    Dim last_row As Integer

    last_row = Cells(Rows.Count, 1).End(xlUp).Row ‘This line gets the last row

    Debug.Print last_row 

End Sub

```

- After that, you need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Save-the-Code-25-1024x339.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- Then, you need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/Run-the-Code-12.png)<figcaption>Run the Code</figcaption>

- Finally, you will get  **output ** as given below in the Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/Final-output-3.png)<figcaption>Final output</figcaption>

### Find Last Non-Blank Column in a Row

- Firstly, in the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Sub getLastUsedCol()

    Dim last_col As Integer

    last_col = Cells(4,Columns.Count).End(xlToLeft).Column ‘This line gets the last column

    Debug.Print last_col

End Sub

```

- After that, you need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Col-Save-the-Code-1024x319.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- Then, you need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/Col-Run-the-Code.png)<figcaption>Run the Code</figcaption>

- Finally, you will get  **output ** as given below in the Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/Col-Output.png)<figcaption>Output</figcaption>

### Select Data Set in Excel Using VBA

- Firstly, in the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Sub select_table()
Dim last_row, last_col As Long

'Get last row
last_row = Cells(Rows.Count, 2).End(xlUp).Row

'Get last column
last_col = Cells(4, Columns.Count).End(xlToLeft).Column

'Select entire table
Range(Cells(4, 2), Cells(last_row, last_col)).Select

End Sub

```

- After that, you need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/DataSet-Save-the-Code.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- Then, you need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/DataSet-Run-the-Code.png)<figcaption>Run the Code</figcaption>

- Finally, you will get  **output ** as given below in the Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/DataSet-Output.png)<figcaption>Output</figcaption>

### Benefits of this method

- We literally wrote only one line to get last row with data. This makes it easy.
- Less line of code, less time taken.
- Easy to understand.
- Works perfectly if you have a clumsy data table with fixed starting point.

### Cons of Range.End method

- The starting point must be known.
- You can only get last non-blank cell in a known row or column. When your starting point is not fixed, it will be useless. Which is very less likely to happen.

## Find Last Row Using Find() Function

- Firstly, in the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Sub last_row()

   lastRow = ActiveSheet.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
 
   Debug.Print lastRow

End Sub

```

- After that, you need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Table-Save-the-Code-1024x266.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- Then, you need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/Table-Run-the-Code.png)<figcaption>Run the Code</figcaption>

- Finally, you will get  **output ** as given below in the Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/Table-Output-1024x375.png)<figcaption>Output</figcaption>

### Benefits of Find function

- You don’t need to know the starting point. It just gets you last row.
- It can be generic and can be used to find last cell with data in any sheet without any changes.
- Can be used to find any last instance of specific text or number on sheet.

### Cons of Find() function

- It is ugly. Too many arguments.
- It is slow.
- Can’t use to get last non blank column. Technically, you can. But it gets too slow.

## Using SpecialCells Function To Get Last Row

- Firstly, in the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
 Sub spl_last_row_()
lastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
Debug.Print lastRow
End Sub

```

- After that, you need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Save-the-Code-2-1.png)

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- Then, you need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/Ex-2-Run-the-Code.png)<figcaption>Run the Code</figcaption>

- Finally, you will get  **output ** as given below in the Excel.

![](https://geekexcel.com/wp-content/uploads/2021/09/Output-2.png)<figcaption>Output</figcaption>

## A Brief Synopsis

Here, we have explained the step-by-step procedure ** on how to find the last Non-Blank row and column using VBA**. Make use of this. Please share your worthwhile  **feedback**  in the below  **comment**  section. To learn more, check out our website **[Geek Excel](https://geekexcel.com/)!!**

**Keep Reading:**

- **[Excel Formulas to Check If Cell Value is Greater than Given Criteria!!](https://geekexcel.com/excel-formulas-if-cell-value-is-greater-than-given-criteria/)**
- **[Formulas for Counting the Cells Greater than a Given Values in Excel!!](https://geekexcel.com/formulas-for-counting-the-cells-greater-than-a-given-values-in-excel/)**
- **[Excel Formulas to Sum the Values Greater than a Certain Date!!](https://geekexcel.com/excel-formulas-to-sum-the-values-greater-than-a-certain-date/)**
- **[Excel Formulas to Sum the Values that are Greater than Certain Value!!](https://geekexcel.com/excel-formulas-to-sum-the-values-that-are-greater-than-certain-value/)**
- **[Excel Formulas to Highlight Values Greater than a Certain Value!!](https://geekexcel.com/excel-formulas-to-highlight-values-greater-than-a-certain-value/)**