I was following suggestions under question How to avoid using Select in Excel VBA macros, but still getting "Application-defined or object-defined error".
My macro suppose to check value in one of lines, compare it with set value, and if values equals, then copy line to another sheet. I tried to avoid usage of .Select command, but no matter what I try I'm getting errors.
This is my last version:
Counter2 = 17
For Counter1 = 12 To 150
Dim S As Worksheet
Dim R As Worksheet
Dim SL As Range
Dim RL As Range
Set R = Sheets("Front")
Set S = Sheets("CHECK LIST")
Set SL = S.Range(Cells(Counter1, 1), Cells(Counter1, 10))
Set RL = R.Range(Cells(Counter2, 1), Cells(Counter2, 10))
Set curCell = Worksheets("CHECK LIST").Cells(Counter1, 6)
Set checkCell = Worksheets("Front").Cells(3, 5)
If curCell.Value = checkCell.Value Then
With S
.SL.Copy
End With
With R
.RL.PasteSpecial
End With
Counter2 = Counter2 + 1
End If
Next Counter1
Is this something to do with usage of variables (Counter1, Counter2) in Range?
SL
andRL
– chanceaS.Range(S.Cells(Counter1, 1), S.Cells(Counter1, 10))
and so on – Rory