Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ISERROR(VLOOKUP) in VB

Status
Not open for further replies.

laurenbattaglia

Technical User
May 3, 2002
28
US
I am using VB6 in Excel to do a comparitive of two tables and copy if a vlookup value does not exist in the lookup array. I am using the following code, but the value keeps coming up false.

Dim vLookupValue
Dim C As Integer
Dim lngLastRow As Long




Workbooks.Open FileName:="O:\Lauren\Comparatives\SEC DB TEMP.xls"
Sheets("BALANCE_SHEET").Select
Windows("SEC DB TEMP.xls").Activate
Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Sort Key1:=Range("I2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

Windows("SEC DATABASE V2.xls").Activate
Sheets("BALANCE_SHEET").Select
Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Sort Key1:=Range("I2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom


'Do comparative to replace old duplicate data
C = 2
lngLastRow = Workbooks("SEC DATABASE V2.xls").Worksheets("Balance_Sheet").Range("I65536").End(xlUp).Row
lngLastRow = lngLastRow + 1

Windows("SEC DATABASE V2.xls").Activate
Sheets("Balance_Sheet").Select
Range("I" & C).Select




vLookupValue = Workbooks("SEC DATABASE V2.xls").Worksheets("Balance_Sheet").Range("I" & C)

Do Until C = lngLastRow
If Application.WorksheetFunction.IsError("VLookup(vLookupValue, '[SEC DATABASE V2.xls]BALANCE_SHEET'!$i$1:$i$" & Range("I1").End(xlDown).Row & ", 1, False)") Then
Windows("SEC DATABASE V2.xls").Activate
Sheets("Balance_Sheet").Select
Range("I" & C).Select
ActiveCell.EntireRow.Copy
Windows("SEC DB TEMP 2.xls").Activate
Sheets("BALANCE_SHEET").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(rowOffset:=1, ColumnOffset:=0).Activate
ActiveSheet.Paste
Application.CutCopyMode = False


End If
C = C + 1

Loop


Thanks for any help you can give me,

Lauren
 

>I am using VB6 in Excel

Sounds like you are using VBA in Excel.
Then ask in the VBA forum707
This is the VB 5 & 6 forum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top