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
 

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,331
Messages
5,601,006
Members
414,420
Latest member
Richie77777

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