Excel Macro user function used in several sheets in same workbook

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
 
G

gimme_this_gimme_that

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top