Last five entries

ExcelRoy

Well-known Member
Joined
Oct 2, 2006
Messages
2,540
Office Version
  1. 365
Platform
  1. Windows
hi,

hopefully someone can help me out here, im a little stuck for a formula?

i have a range K28:K97 with numbers in each cell, now starts at row 28, but every week or so a new number is added upto a maximum of 97 (sometimes not that many)

what i would like is a formula to show only the last 5 entries

hope someone can help me out here

thanks in advance
 
Hi Domenic,

As requested

Code:
Private Sub CommandButton1_Click()
rows("9:97").Hidden = Not rows("9:97").Hidden
End Sub
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try...

Code:
Private Sub CommandButton1_Click()
Rows("9:97").Hidden = Not Rows("9:97").Hidden
[COLOR="Red"]Application.Calculate[/COLOR]
End Sub

Code:
Public Function MultiConCatLast5(ByRef rRng As Range, Optional ByVal sDelim As String = "") As String
    [COLOR="Red"]Application.Volatile[/COLOR]
    Dim i As Long
    Dim j As Long
    j = 0
    For i = 1 To rRng.Count
        If rRng(i) <> "" Then
            j = j + 1
            MultiConCatLast5 = MultiConCatLast5 & sDelim & rRng(i).Text
            If j = 5 Then Exit For
        End If
    Next i
    MultiConCatLast5 = Mid(MultiConCatLast5, Len(sDelim) + 1)
End Function
 
Upvote 0
Perfect, works a dream, thanks

Just curious, but what does the application.volatile mean and do?
 
Upvote 0
Perfect, works a dream, thanks

You're welcome!

Just curious, but what does the application.volatile mean and do?

It ensures that the function is recalculated whenever a calculation occurs in any cells on the worksheet. Apparently, when the rows are hidden, it triggers a re-calculation. However, for some reason, the calculation does not get completed, hence the function returns #VALUE!. By placing Application.Calculate within the event macro, it forces a re-calculation. Since Application.Volatile is included in the function, it re-calculates and returns the desired result.
 
Last edited:
Upvote 0
Actually, I meant to say...

It ensures that the function is recalculated whenever a calculation occurs in any cells on the worksheet. Apparently, when the rows are hidden, it triggers the function to re-calculate. However, for some reason, the calculation does not get completed, hence the function returns #VALUE!. By placing Application.Calculate within the event macro, it forces a re-calculation. Since Application.Volatile is included in the function, it re-calculates and returns the desired result.
 
Upvote 0

Forum statistics

Threads
1,214,893
Messages
6,122,121
Members
449,066
Latest member
Andyg666

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