
Last_Row = Cells(Rows.Count, 1).End(xlUp) Step 5: Use a combination of End key and xlUp to go to the last non-empty row in excel. The same logic we are going to use in the next line of code. Now, what if you are at the last cell of the excel and want to go up to the last non-empty row? You’ll use Ctrl + Up Arrow, right?
#VISUAL BASIC FOR EXCEL STARTER CODE#
This means this code allows the system to go to the last cell of Excel. This code allows VBA to find out the total number of (empty + non-empty) rows present in the first column of the excel worksheet. The value numeric 1 is synonyms to the first column in the excel sheet. Step 4: Mention 1 after a comma in the above-mentioned code. Step 3: Type the code starting with CELLS (Rows.Count in front of Last_Row =. Step 2: Use the defined variable to hold the value of the last non-empty row.


Here, the variable Last_Row is defined as LONG just to make sure it can take any number of arguments. Step 1: Define a variable which can take value for the last non-empty row of the excel column. On similar lines, follow the below steps for creating code in VBA to reach to the last non-empty row of a column in Excel. Well, this method is as same as using the Ctrl + Down Arrow in Excel to go to the last non-empty row. You can download this VBA Last Row Excel Template here – VBA Last Row Excel Template Example #1 – Using Range.End() Method
#VISUAL BASIC FOR EXCEL STARTER HOW TO#
How to Find Last used Row in Column Using VBA?īelow are the different examples with different methods to find the last used Row of a Column in Excel using VBA Code. In this article, I will introduce some methods which can be useful in finding out the last row for a given data set using VBA code. This is the reason a dynamic code which can take the last filled row into consideration makes it more important for us. Reason for the same is the range which we have updated under WorksheetFunction (which is B2:B11). Logically speaking, the above code will not sum up all the 14 rows from column B. Now, what if I add some cells to this data and run this code again? Here, this code prints the sum of salaries for all employees (cell B2:B11) in cell D2. Range("D2").Value = WorksheetFunction.Sum(Range("B2:B11"))

Suppose I have data as given below with employee and their salaries. Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.
