Knockoutpie
Board Regular
- Joined
- Sep 10, 2018
- Messages
- 116
- Office Version
- 365
- Platform
- Windows
Occasionally the searched value is not found, when that happens. I get an error 91 (because the value doesn't exist)
What's the proper way to handle this without using "ON Error"
What's the proper way to handle this without using "ON Error"
VBA Code:
'Activate worksheet
Worksheets("Quote").Activate
'Copy/search part Num
Dim str1 As String
Dim Cntr As Integer
Dim Row As Integer
Cntr = 0
Row = 2
'Start of loop
Do While Cntr <= 650 ' should not loop over 650 rows
Cells.Find(What:="PartNum").Offset(Row, 0).Select ' Find "partnum" in row 3, offset and copy value
' Find the return value
Cntr = Cntr + 1
str1 = ActiveCell.Value
Selection.Copy
Worksheets("Export").Activate
ActiveCell.Select
' search for copied value in Export worksheet
Cells.Find(What:=str1, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
Cells.FindNext(After:=ActiveCell).Activate
' when copied value is found, copy value from 24 columns to the right
ActiveCell.Offset(0, 24).Range("A1").Select
Selection.Copy
Worksheets("Quote").Activate ' return to quote worksheet
'Find LeadTime and determine paste location of new offset copied value
Cells.Find(What:="Leadtime").Offset(Row, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues
Row = Row + 1
Loop