Hi,
I have a piece of code that I've used many times without errors, until today. The code falls over with a error 91 on the second run of the do loop at 'Loop While Not j Is Nothing And j.Address <> firstAddress'. Also on the line before 'Set j = .FindNext(j)', j has a value of nothing. Even though there is another occurance of j to find? Can anyone spot where I've gone wrong?
Thanks for your help,
Knifey
P.S. Please copy & paste into notepad to regain tabulation.
'search field lookup file to find the legacy column title
With wb3.Worksheets(ws3.Name).Columns("C:C").Rows("1:" & endRowFieldLookup)
Set j = .Find(inputColTitle, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows)
'if it is found then..
If Not j Is Nothing Then
'where was it found
firstAddress = j.Address
'a continuous loop
Do
'what column?
legacyValCol = j.Column
'get vars
legacyVal = j.Value
offTableVal = j.offset(0, -2).Value
offSystemFieldVal = j.offset(0, -1).Value
'find offSystemFieldVal in the column headers of MigrationExporter v2.3.xls (correct table/tab).
With wb4.Worksheets(offTableVal).Columns("A:" & endColLetter).Rows("1:1")
Set i = .Find(offSystemFieldVal, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns)
'if it is found then..
If Not i Is Nothing Then
'where was it found
MEPasteCol = i.Column
MEPasteColLetter = ColNo2ColRef(MEPasteCol) 'get title
MEPasteColTitle = i.Value
Set cRange = wb2.Worksheets(ws2.Name).Rows("2:" & endRow).Columns(inputColLetter & ":" & inputColLetter)
Set pRange = wb4.Worksheets(offTableVal).Rows("2:" & endRow).Columns(MEPasteColLetter & ":" & MEPasteColLetter)
cRange.Copy
pRange.PasteSpecial Paste:=xlValues
End If
End With
Set j = .FindNext(j)
'loop while something is found, unless it was the first thing found
Loop While Not j Is Nothing And j.Address <> firstAddress
End If
End With
I have a piece of code that I've used many times without errors, until today. The code falls over with a error 91 on the second run of the do loop at 'Loop While Not j Is Nothing And j.Address <> firstAddress'. Also on the line before 'Set j = .FindNext(j)', j has a value of nothing. Even though there is another occurance of j to find? Can anyone spot where I've gone wrong?
Thanks for your help,
Knifey
P.S. Please copy & paste into notepad to regain tabulation.
'search field lookup file to find the legacy column title
With wb3.Worksheets(ws3.Name).Columns("C:C").Rows("1:" & endRowFieldLookup)
Set j = .Find(inputColTitle, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows)
'if it is found then..
If Not j Is Nothing Then
'where was it found
firstAddress = j.Address
'a continuous loop
Do
'what column?
legacyValCol = j.Column
'get vars
legacyVal = j.Value
offTableVal = j.offset(0, -2).Value
offSystemFieldVal = j.offset(0, -1).Value
'find offSystemFieldVal in the column headers of MigrationExporter v2.3.xls (correct table/tab).
With wb4.Worksheets(offTableVal).Columns("A:" & endColLetter).Rows("1:1")
Set i = .Find(offSystemFieldVal, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns)
'if it is found then..
If Not i Is Nothing Then
'where was it found
MEPasteCol = i.Column
MEPasteColLetter = ColNo2ColRef(MEPasteCol) 'get title
MEPasteColTitle = i.Value
Set cRange = wb2.Worksheets(ws2.Name).Rows("2:" & endRow).Columns(inputColLetter & ":" & inputColLetter)
Set pRange = wb4.Worksheets(offTableVal).Rows("2:" & endRow).Columns(MEPasteColLetter & ":" & MEPasteColLetter)
cRange.Copy
pRange.PasteSpecial Paste:=xlValues
End If
End With
Set j = .FindNext(j)
'loop while something is found, unless it was the first thing found
Loop While Not j Is Nothing And j.Address <> firstAddress
End If
End With