PDA

View Full Version : Selection box on Vlookup error



jdgalaway
06-07-2013, 12:59 PM
I wrote the following code to VLookup codes in a worksheet. Currently, I just highlight cells with errors. Instead, I want a selection pop-up box that includes items that are similar to what is in the cell with the error. I hope this makes sense and someone can help me.

Sub Main()
On Error Resume Next
Err.Clear
Dim i As Integer
For i = 2 To 200
Worksheets("MyPortfolio").Cells(7, i).Value = Application.WorksheetFunction.VLookup(Worksheets _
("MyPortfolio").Cells(7, i), Worksheets("sheet1").Range("a2:b1428"), 2, False)
If Err <> 0 Then
GoTo Line1
Resume Next
Else
Resume Next
End If
Next i
Dim x As Integer
For x = 2 To 200
If Not IsNumeric(Worksheets("MyPortfolio").Cells(7, x).Value) Then
Worksheets("MyPortfolio").Cells(7, x).Interior.ColorIndex = 6
End If
Next x
Line1:
End Sub

SamT
06-08-2013, 07:32 AM
This bit of code
If Err <> 0 Then
GoTo Line1 ' = Exit Sub
Resume Next 'This line is never seen
Else
Resume Next '= Next line (End IF) and Err = 0
End If
Can be done with
If Err <> 0 Then Exit Sub Try this

For i = 2 To 200
NextRow:
Worksheets("MyPortfolio").Cells(7, i).Value = Application.WorksheetFunction.VLookup(Worksheets _
("MyPortfolio").Cells(7, i), Worksheets("sheet1").Range("a2:b1428"), 2, False)
If Err <> 0 Then
Err = 0
i = i+1
GoTo NextRow
End If
Next i


I want a selection pop-up box that includes items that are similar to what is in the cell with the error. If Err <> 0 Then
Err = 0
ShowSimilar i
i = i+1
GoTo NextRow Sub ShowSimilar(i As Long)
Dim Problem As String
Problem = Worksheets("MyPortfolio").Cells(7, i)
'and more stuff to do what you want