ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel Macro user function used in several sheets in same workbook (https://www.excelbanter.com/excel-programming/424908-excel-macro-user-function-used-several-sheets-same-workbook.html)

Felipe Montoya

Excel Macro user function used in several sheets in same workbook
 
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

[email protected][_2_]

Excel Macro user function used in several sheets in same workbook
 
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



All times are GMT +1. The time now is 12:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com