Common functions location.

welshgasman

Well-known Member
Joined
May 25, 2013
Messages
1,395
Office Version
  1. 2019
  2. 2007
Platform
  1. Windows
Hi all,
I use various self created functions in my Excel workbooks.
One such function might be GetLastRow() where I pass in a sheet and column name and get back the last used row.

This save me trying to remember the syntax, especially with my memory these days. :(
I save these in my personal.xlsb workbook.

Works fine, but I have just realised that if I have to give a workbook to someone else, they will not have my Personal.xlsb, but their own, if they even have one.

Other than having to copy the functions into multiple workbooks, is there any other method I could use please?

TIA
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
It depends on how you are using them, and your setup. If you are calling them from cells, then you'll probably want to put them in an add-in which ideally you would store in a network location, otherwise the formula path (which you won't see normally) won't be the same on the other user's machine if the add-in is stored locally.
 
Upvote 0
No, I call them from other vba.
Eg, I asked a question in another thread
and ended up, just copyìg the formula to the rows. In that scenario, I used my GetLastRow function.
I run this from workshop open.
However if I give that workbook to.my diabetic nurse, it is not going to find that function.
 
Upvote 0
BTW I am not getting any email notifications, despite having them set in preferences?

An example.
In my Blood Pressure Workbook I have

Code:
Option Explicit

Private Sub Workbook_Open()
Dim lngLastRow As Long
'Refresh sheet to get lastet data.
ActiveWorkbook.RefreshAll
'Get last row in A in sheet qryPresure
Sheets("qryPressure").Select
lngLastRow = getlastrow(ActiveSheet.Name) '.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
'Copy formula in F2 down.
Range("F2").Copy
Range("F2:F" & lngLastRow).PasteSpecial xlPasteFormulas
Range("F" & lngLastRow).Select
Sheets("Chart").Select
ActiveWorkbook.Save
End Sub
and in my Personal.xlsb I have
Code:
Public Function GetLastRow(pstrSheet As String, Optional pstrColumn As String) As Long
' Return last used row for sheet and column passed in
Dim lngLastRow As Long
Dim sht As Worksheet

Set sht = Sheets(pstrSheet)
If pstrColumn = "" Then pstrColumn = "A"

lngLastRow = sht.Cells(ActiveSheet.Rows.Count, pstrColumn).End(xlUp).Row
GetLastRow = lngLastRow
Set sht = Nothing

End Function

Now of course, it is only a snippet and I could copy it into the BP workbook.
However if I decide to enhance that is some way (same would apply to other functions) then I have to recopy.

I have not used any addins in Excel.
How would I go about that, and presumably that addin moves with the workbook?
 
Upvote 0
Unless you have set a reference to your personal macro workbook, that code will only work if the getlastrow function is also in the BP workbook already.
 
Upvote 0
Sorry, my memory is not what it was. :(

Yes, I can see I set a reference to the Personal.xlsb and can now remember doing it after searching on how. :(

However, now that is there, if I was to give you the workbook, would it still work?
I know it would not find the data, as that comes from an Access DB on this laptop. So I suppose in this case there is no real need as the Refresh is not going to increase the rows of data. It is still going to run however as it is in the Workbook.Open event?
However if this was another function that *could* produce another result, would that work, if I sent it to you, for example.?
 

Attachments

  • Screenshot 2024-10-18 191806.png
    Screenshot 2024-10-18 191806.png
    36.9 KB · Views: 2
Upvote 0
No, because I don’t have the code, so the reference would be broken.
Unless you have a lot of workbooks you need to share, I’d just copy the relevant code across.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,886
Messages
6,175,189
Members
452,616
Latest member
intern444

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