I am having trouble with defining a range using custom functions. Here is the main macro:
'1 Selección del archivo de nóminas
Dim nominas_wb As Workbook
Dim nominas_path As Variant
nominas_path = Application.GetOpenFilename(Title:="Seleccione el archivo de nóminas que desee añadir al repositorio:")
If nominas_path <> False Then
Set nominas_wb = Workbooks.Open(nominas_path)
ElseIf nominas_path = False Then
Exit Sub
End If
Dim nominas_ws As Worksheet
Set nominas_ws = nominas_wb.Worksheets(1)
'2 Definiendo las dimensiones del archivo de nóminas
Dim nominas_range As Range
nominas_range = nominas_ws.Range(Cells(1, 1), Cells(last_row_index(nominas_ws, 5), last_column_index(nominas_ws, 1)))
... and here are the functions:
Function last_row_index(target_worksheet As Worksheet, target_column_index As Long) As Long
last_row_index = target_worksheet.Cells(Rows.Count, target_column_index).End(xlUp).Row
End Function
Function last_column_index(target_worksheet As Worksheet, target_row_index As Long) As Long
last_column_index = target_worksheet.Cells(target_row_index, Columns.Count).End(xlToLeft).Column
End Function
The error itself is an error 91 on the nominas_range = ... line.