Excel Macro user function used in several sheets in same workbook

  • Thread starter Thread starter Felipe Montoya
  • Start date Start date
F

Felipe Montoya

I have created a macro function to reference tha last cell used in a column
and returns the data in it to another cell in the sheet. It works fine for
just one sheet within the same workbook. But if I use the function in
another sheet, it returns the value from the previous sheet.

Can anybody help me solve it so that I can get the value that correspond to
each sheet. Below is the code I am using

Function UltimaFecha(Fecha As Date, celda As String) As Date
Application.Volatile
Fecha = Cells(Cells.Rows.Count, celda).End(xlUp).Value
UltimaFecha = Fecha
End Function
 
Modify your definition of UltimaFetcha:

UltimaFetcha (new Date,"some text", ThisWorkbook.Sheets("sheetname")

Function UltimaFecha(Fecha As Date, celda As String, sheet as
WorkSheet) As Date
Application.Volatile
  Fecha = sheet.Cells(sheet.Cells.Rows.Count, celda).End(xlUp).Value
  UltimaFecha = Fecha
End Function
 
Back
Top