Vlookup Seems to Work, but Still Throws Error Code (1004)

MarsBars

New Member
Joined
May 21, 2014
Messages
27
Good Morning,

I have a vlookup that keeps throwing an error code, but only after it has completed it's job. It will populate all of the cells in the desired range with the correct values and then throw the error. Can anyone tell me what's going wrong with this?


Code:
Dim v As Integer
v = 2
Do While Cells(v, 1) <> ""
Dim Bvalue As String
Bvalue = Application.WorksheetFunction.VLookup(Report.Sheets(2).Cells(v, 1).Value, _
Workbooks("Internal.xls").Sheets(1).Range("A:G"), 7, False)
Report.Sheets(2).Cells(v, 2).Value = Bvalue
v = v + 1
Loop

Thanks in advance!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
why do you type "Report.sheets(2)"? why not sheets(2)?
in addition, change the range into
Code:
range(Workbooks("Internal.xls").Sheets(1).columns(1), Workbooks("Internal.xls").Sheets(1).columns(7))
 
Upvote 0
Try this.
Code:
Dim v As Integer
Dim BValue As Variant

    v = 2
    
    Do While Cells(v, 1) <> ""

        With Report.Sheets(2).Cells(v, 1)

            BValue = Application.VLookup(.Value, Workbooks("Internal.xls").Sheets(1).Range("A:G"), 7, 0)

            If Not IsError(BValue) Then
                Report.Sheets(2).Cells(v, 2).Value = BValue
            End If

        End With

        v = v + 1

    Loop
 
Upvote 0
Thanks for the help. Unfortunately my computer froze and I lost this part of the code (and more). I will reconstruct it tomorrow or monday, and let you know if one of those suggestions works. Sorry for the delay.
 
Upvote 0

Forum statistics

Threads
1,215,637
Messages
6,125,965
Members
449,276
Latest member
surendra75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top