Multiply two variables that contain ranges

2

I am trying to multiply two variables (be ContractsQty and LeaseQty ) to get the total of lines that have to be created.

I'm trying to use something like this:

'Calcular cantidad de lineas
Dim ContractsQty As Range
Set ContractsQty = vcr.Range("Q2:Q" & Cells(Rows.Count, 17).End(xlDown).Row)
Dim LeaseQty As Range
Set LeaseQty = Sheets("Pivot").Range("B2:B" & Cells(Rows.Count, 2).End(xlDown).Row)
Dim TotalLines As Long
Dim TotalContracts As Long
TotalContracts = ContractsQty.Count
Dim TotalLease As Long
TotalLease = LeaseQty.Count
Dim TotalofLines As Integer
TotalofLines = TotalContracts * TotalLease

but throws the error

"Run-time error '6':" Overflow 
    
asked by Santiago Di Fiore 16.01.2018 в 20:46
source

1 answer

1

It is for details in the code, highlight them with comments in their respective line:

Dim ContractsQty As Range
    Set ContractsQty = vcr.Range("Q2:Q" & Cells(Rows.Count, 17).End(xlUp).row) 'Usar xlUp en lugar de xlDown
Dim LeaseQty As Range
    Set LeaseQty = Sheets("Pivot").Range("B2:B" & Cells(Rows.Count, 2).End(xlUp).row) 'Usar xlUp en lugar de xlDown
Dim TotalLines As Long
Dim TotalContracts As Long
    TotalContracts = ContractsQty.Rows.Count 'Cuenta total de filas
Dim TotalLease As Long
    TotalLease = LeaseQty.Rows.Count 'Cuenta total de filas
Dim TotalofLines As Integer
    TotalofLines = TotalContracts * TotalLease
    
answered by 17.01.2018 в 02:19