I used to have a line
Set rRng1 = Worksheets("Sheet1").Range("I2:J20")
But as the range of cells can change from file to file (I2 is constant though), I found out an easy way to automate it.
The first cell from the range is always I2, and the last cell is J(last_pair_cell)
I thought that using Range(Cells(2,9), Cells(last_pair_cell), 10) would to the trick, but I'm getting error 1004...
This is the entire code:
Sub LoopRange2()
Dim rCell1 As Range
Dim rCell2 As Range
Dim rRng1 As Range
Dim rRng2 As Range
Dim nCol As Integer 'Finds week column to insert values
nCol = Worksheets("Clube").Range("P69").Value + 5
'Find number of pairs that played the tournment
Dim last_pair_cell As Integer
Dim rngX As Range
Set rngX = Worksheets("Sheet_CSV").Range("A1:A10000").Find("Board", lookat:=xlPart)
If Not rngX Is Nothing Then
last_pair_cell = rngX.Row - 1
End If
**Set rRng1 = Worksheets("Sheet_CSV").Range(Cells(2, 9), Cells(last_pair_cell, 10))**
'Set rRng1 = Worksheets("Sheet1").Range("I2:J20")
Set rRng2 = Worksheets("Clube").Range("C3:C80") 'IF ERROR CHANGE C80 TO C69
For Each rCell1 In rRng1.Cells
For Each rCell2 In rRng2.Cells
If rCell2.Value = rCell1.Value Then
Worksheets("Clube").Cells(rCell2.Row, nCol).Value = Worksheets("Sheet1").Cells(rCell1.Row, 6).Value
End If
Next rCell2
Next rCell1
End Sub