Find Last entry

GinoZ

Board Regular
Joined
Feb 6, 2006
Messages
169
Hey guys, I have the following array

Code:
A   B    C    D   E

1   5    A    4    5
2   6    V    5    4
3   4         6    3
4   7    W         3
5   0    0    0    0 
6   0    0    0    0

The fist column represents day. I need a VBA-code to find the last day that is filled in. Day that are not filled in have zero's as entry. n this example i want to find day 4. Some spaces are blanc.
Thanks in advance

Gino
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Lewiy

Well-known Member
Joined
Jan 5, 2007
Messages
4,284
Give this a try:
Code:
Sub MyMacro()
Dim Limit As Long
Dim c As Long
Limit = Cells(Rows.Count, 1).End(xlUp).Row
For c = Limit To 1 Step -1
    If Cells(c, 1) <> 0 Then
        MsgBox "Last day entered was day " & c
        Exit Sub
    End If
Next c
End Sub
 

GinoZ

Board Regular
Joined
Feb 6, 2006
Messages
169
Not exactly what I meant. This macro returns the last row filled in row in my sheet. It needs to lookup in the arrey and return the last row that has data greater than zero or nothing in it.
 

Lewiy

Well-known Member
Joined
Jan 5, 2007
Messages
4,284
Sorry, I see what I did:
Code:
Sub MyMacro() 
Dim Limit As Long 
Dim c As Long 
Limit = Cells(Rows.Count, 2).End(xlUp).Row 
For c = Limit To 1 Step -1 
    If Cells(c, 2) <> 0 Then 
        MsgBox "Last day entered was day " & c 
        Exit Sub 
    End If 
Next c 
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,376
Messages
5,836,896
Members
430,461
Latest member
flavgf

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top