Link to home
Start Free TrialLog in
Avatar of Taras
TarasFlag for Canada

asked on

Row number of last non null value in one excel column

I am using Access 2010 I need to find last non null value in column “A” in my excel file.
My excel file –workbook is on C:\Inventory\Name_aa.xlsx.
In my Name_aa.xlsx workbook I have two worksheets. I need info from first worksheet , one named” Validation” and its column “A”.
To be precise I need function to give me row number of last non null values of this column.
I need this as  VBA code not as excel solution,,INDEX MATCH and ….
ASKER CERTIFIED SOLUTION
Avatar of Helen Feddema
Helen Feddema
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of McOz
McOz

You could use some code like this. It displays a message of the last non-null row in column 1 ("A"):

MsgBox ThisWorkbook.Sheets("Validation").Cells(Rows.Count, 1).End(xlUp).Row

Open in new window

Taras,

I believe something like this should help you.
Sub get_last_non_null_row_value()
    Dim rowValue As Long
    sheets("Validation").select
    Range("A1").Select
    Selection.End(xlDown).Select
    rowValue = ActiveCell.Row
    'instead of displaying this dialog box, you might want to populate 
    'the value somewhere else in the workbook or return the value to a calling function, etc.
    MsgBox "last row value is " & rowValue
End Sub

Open in new window


I should point out that this example assumes there are no null values in between non-null values in column A. If there are null values in between non-null values, it will return the row value of the row just above the first null value.

Good luck!
Avatar of Taras

ASKER

Helen.
I am not sure why this happening, however I am getting not correct result , I am getting value of last rows in my worksheet.
I can see that last value is seating in A15, after that cells in column A are empty, however I got as result of function  last row is 378 is that because there is formula behind in every filed in column A. “=IFERROR(…..and on
Are you defining a cell being Null as strictly that (it contains a Null), or perhaps thinking of empty cells, or cells with empty strings in them?  (or formulas, for that matter?)  I was testing in a workbook with no formulas.
Can you post the workbook for testing?
Avatar of Taras

ASKER

here is formula behind all those cells in Column "A".
I picked up just cell A16 as it was first empty cell after A15.

=IFERROR(INDEX(Parts_detail,$A16,COLUMN()-1),"").
If I go to cell A17 it has :
=IFERROR(INDEX(Parts_detail,$A17,COLUMN()-1),"") and on.
It looks if it hit error it should show  ""  empty string.
I was not right when I said last cell with “ non null” value. I made mistake, sorry.
For me row number of last not empty cell in column “A” is row which shows visible data in column “A” cell.
In my case it is A15
It is not row number of column “A” cell  that do not show data and has formula in or has empty string “” which is not visible.