0

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.

  • 1
    Try to add a `Set` before _nominas_range =_ – Shrotter Jun 02 '22 at 10:28
  • Thank you! Any tips on how to find such simple mistakes? Often times I will go over my code multiple times trying to understand what I have done wrong and I will find issues with the logic of my loops or mistakes with variables, but that sort of simple syntax mistake always eludes me. –  Jun 02 '22 at 10:32

0 Answers0