how to get the number of the last row?

Lottoguy

New Member
Joined
May 27, 2016
Messages
40
I have sheets with many numbers in many rows and columns. I m making a statistic about the time, so the number on a row below the other one means that numbers showed up later. There are numbers that are in the sheet more than once, in a different row and column, but what I need is how to get the number of the last row that number is on? I m not sure if excel has a formula for it or if I have to write a macro to do it. If I have to write a macro, tell me how to do it if you can help.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Here's a lightly tested macro you can try:
VBA Code:
Sub GetLastRowNum()
Dim R As Range, x
Set R = ActiveSheet.UsedRange
On Error Resume Next
Set x = R.SpecialCells(xlCellTypeConstants, xlNumbers).Find("*", , , xlWhole, , xlPrevious)
On Error GoTo 0
If Not x Is Nothing Then
    MsgBox "LastNumber is in row " & x.Row & " and column " & x.Column & " of the used range in the active sheet"
Else
    MsgBox "Can't find last row with a number on the activesheet"
End If
    
End Sub
 
Upvote 0
Hi Lottoguy, you may also try a simple formula below, note it requires the numbers in selection are consecutive without blank or text, otherwise needs tweaks

Book1
ABC
1Number
29Last number
367
41
57
66
77
87
93
104
117
Sheet2
Cell Formulas
RangeFormula
C3C3=INDEX(A2:A20,COUNT(A2:A20),1)
 
Upvote 0
Option If there are Blank Cells

Book1
ABC
1Number
29Last number
3620
41
57
6<< Blank Cell
77
8<< Blank Cell
93
104
117
12<< Blank Cell
1320
14
15
Sheet2
Cell Formulas
RangeFormula
C3C3=LOOKUP(2,1/(NOT(ISBLANK(A:A))),A:A)
 
Upvote 0
Here's a lightly tested macro you can try:
VBA Code:
Sub GetLastRowNum()
Dim R As Range, x
Set R = ActiveSheet.UsedRange
On Error Resume Next
Set x = R.SpecialCells(xlCellTypeConstants, xlNumbers).Find("*", , , xlWhole, , xlPrevious)
On Error GoTo 0
If Not x Is Nothing Then
    MsgBox "LastNumber is in row " & x.Row & " and column " & x.Column & " of the used range in the active sheet"
Else
    MsgBox "Can't find last row with a number on the activesheet"
End If
   
End Sub
This macro is showing the number of the last row and column that my last number is in my range. But its not what I need to do. What I need is to get the number of the last row that all numbers are in my range. I have numbers from 01 to 5451, in the range of A1:R594. Many numbers are in the range more than once, some are 2,3 and 4 times. I just need the number of the last row that they are. Like if a number shows up 4 times in my range, I only need to know the last row that it is.
 
Upvote 0
Is this what you mean
+Fluff 1.xlsm
ABCDEFGHIJKLMNOPQRSTU
1529628295295326839645184110344084482062463725514874377449625551834736
239141550467412312721365537624159310115691029439749261180220318927053614
3252939853192238947129195792215278537631822750317311071948385632811322149919
45200141633383048224918022833149531561148610332334991658413851438214456
516213798308432234102329237912700169293014163293346944305393152028032913
649191417282214819864033118212716130165155244724534818433199017330
7418311781507158535485742443957508522101831202517158193086418046222653
841052015110420925286370954442051443427519191670477714224435332732764153
92101251426892622517627933827614488321945371263436364074259812762184379
1014993408157266161503257019445161840486111134581589283935036132401
11401215521632615502933964152791485938029553686351743281747342840981054
1232791250287928362712497343981352575159324095207226044682246379614994684
1346034712402526944382884117139229282271837415299221793782414743541322
141433323184836351174703313180884613453207134604510185535753844358
152410238328273682237016363348112575636192920265316145112273455930183441
162159359739633502212130137021193215014294142253145732714378488810461897
171355539448973347467475026374941424052209653152513392221652662654950
18407234743397220021803945266373620021888355815881658305738431362863107
1943946561766146543171596149941643953114149292140289116571290116152882556
201802502842431513792406296858523711913148710115218403942050729682004
21
Main
Cell Formulas
RangeFormula
U3U3=AGGREGATE(14,6,(ROW(A1:A20)-ROW(A1)+1)/(A1:R20=T3),1)
 
Upvote 0
No, you can just use the formula. :)
 
Upvote 0
No, he showed you the formula as well at the bottom ;) or you could hover over or click U3 to see it.

1613430553371.png
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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
Back
Top