I am matching data in cells on different worksheets in the same workbook. When the data matches I copy some data from sheet 1 to sheet 2.
If they do not match I insert a string where the data would have gone on sheet 2. In many cases there will be multiple records with the same unmatchable data element, I need cycle through all such records until I get to a different data element. The string is inserted during each iteration where the data would have gone on sheet 2.
When a new data element is reached and if that element turns out to be another element that has no match in sheet 1, I get a; Runtime error 91; ‘Object variable or with block variable not set’. The variable rngGMPCA has no value because a match to variable DAFRPCA could not be found. I have tried to assign a value to GMPCA but I am obviously not using the correct syntax. Can someone tell me how to assign a value to GMPCA at the ‘Set GMPCA …. ‘ line in the code below.
With Sheets("First QT").Range("B1:B2034")
Set rngGMPCA = .Find(rngDAFRPCA, LookIn:=xlValues)
'Moves to next GM PCA and test for match.
Set rngToCopy = rngToCopy.Offset(1, 0)
If rngGMPCA Is Nothing Then
'Records comment in cell with DAFR PCA to alert user
to non-matching problem all the DAFRPCAs have been tested
rngDestin = "No data retreived."
strEscape = rngDAFRPCA.Value
Do Until strEscape <> rngDAFRPCA.Value
'Moves to next GM PCA and test for match.
Set rngDAFRPCA = rngDAFRPCA.Offset(1, 0)
Set rngDestin = rngDestin.Offset(1, 0)
rngDestin = "No data retreived."
Loop
With Sheets("First QT").Range("B1:B2034")
Set rngGMPCA = .Find(rngDAFRPCA, LookIn:=xlValues)
If rngGMPCA Is Nothing Then
'Set rngGMPCA =
End If
Set rngToCopy = rngToCopy.Offset(1, 0)
Set rngDestin = rngDestin.Offset(1, 0)
End With
End If
End With
End If
Loop
End Sub
If they do not match I insert a string where the data would have gone on sheet 2. In many cases there will be multiple records with the same unmatchable data element, I need cycle through all such records until I get to a different data element. The string is inserted during each iteration where the data would have gone on sheet 2.
When a new data element is reached and if that element turns out to be another element that has no match in sheet 1, I get a; Runtime error 91; ‘Object variable or with block variable not set’. The variable rngGMPCA has no value because a match to variable DAFRPCA could not be found. I have tried to assign a value to GMPCA but I am obviously not using the correct syntax. Can someone tell me how to assign a value to GMPCA at the ‘Set GMPCA …. ‘ line in the code below.
With Sheets("First QT").Range("B1:B2034")
Set rngGMPCA = .Find(rngDAFRPCA, LookIn:=xlValues)
'Moves to next GM PCA and test for match.
Set rngToCopy = rngToCopy.Offset(1, 0)
If rngGMPCA Is Nothing Then
'Records comment in cell with DAFR PCA to alert user
to non-matching problem all the DAFRPCAs have been tested
rngDestin = "No data retreived."
strEscape = rngDAFRPCA.Value
Do Until strEscape <> rngDAFRPCA.Value
'Moves to next GM PCA and test for match.
Set rngDAFRPCA = rngDAFRPCA.Offset(1, 0)
Set rngDestin = rngDestin.Offset(1, 0)
rngDestin = "No data retreived."
Loop
With Sheets("First QT").Range("B1:B2034")
Set rngGMPCA = .Find(rngDAFRPCA, LookIn:=xlValues)
If rngGMPCA Is Nothing Then
'Set rngGMPCA =
End If
Set rngToCopy = rngToCopy.Offset(1, 0)
Set rngDestin = rngDestin.Offset(1, 0)
End With
End If
End With
End If
Loop
End Sub