VLookup in VBA Error 424: Object required

ctouchberry

New Member
Joined
Dec 4, 2017
Messages
40
Hello,

I'm debugging this as I go, and I'm getting a 424 error on the VLookup line.

I'm trying to load values from "04-Space" in the 2nd column into "JCX" in the 8th column, but only after checking to see if the 04-Space value is in the 1st column in 03-Floor.

The reason for the variables is that while the current data source only has a "Lower Level", other projects might have more than 1 floor, and I also need to account for differences such as "First Floor" and "1st Floor" in the variable.

This is the variable assignment code
Code:
Dim FloorName As String
FloorName = "Lower Level"

This is the other code
Code:
TagRowCounter = 2
Do
    Sheets("04-Space").Cells(TagRowCounter, 2).Value = FloorName
    
    Application.WorksheetFunction.VLookup(FloorName, (Sheets("03-Floor").Cells(TagRowCounter, 1)), 1, False).Value
    
    Sheets("JCX").Cells(TagRowCounter, 8).Value = Sheets("04-Space").Cells(TagRowCounter, 2).Value
    TagRowCounter = TagRowCounter + 1
    
Loop Until Sheets("04-Space").Cells(TagRowCounter, 1) = False

Any thoughts? Thanks in advance!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
The immediate problem is the unnecessary .Value on the end of the VLookup, and the fact that you haven't assigned the value of the VLookup to a variable.

I don't understand what your code is trying to do ... writing the same FloorName to successive rows in "04-Space" and then assigning the same value to successive rows in "JCX"?

But here's one way to do what I think you might be trying to do:

Code:
On Error Resume Next
MatchRow = Application.Match(FloorName, Sheets("03-Floor").Range("A:A"), 0)
On Error GoTo 0
If MatchRow <> 0 Then
    'We have a match in column A!
    'what do you want to do here?
End If
 
Upvote 0
I've updated my code as follows. I'm trying to take a cell from 07-Component, find it on 04-Space, and then load the value in the column to the immediate right into the H/8 column in JCX. This then loops.

I'm looking at rooms in 07-Component, finding the applicable floor in 04-Space, and then loading the floor value into the Floor column in JCX. Does that help?

In 04-Space, Rooms are in Column A, Floors are in Column B.

Code:
'Floor
'Row Column
TagRowCounter = 2
Do
    Sheets("JCX").Cells(TagRowCounter, 8).Value = Application.WorksheetFunction.VLookup(Sheets("07-Component").Cells(TagRowCounter, 2), Sheets("04-Space").Range(A, B), 2, 0)
    TagRowCounter = TagRowCounter + 1
    
Loop Until Sheets("04-Space").Cells(TagRowCounter, 1) = False
 
Upvote 0
Also, that code is giving me a "Run time error 1004: Application-defined or object-defined error" message. Sorry for not including that in my previous post.
 
Upvote 0
Change: Range(A,B) to Range("A:B")

Is your loop boundary correct? On the face of it, it would appear to make more sense to loop until the end of Sheets("07-Component")?

You could also do it without looping:

Code:
LastRow = 99    'Determine this dynamically, e.g. LastRow = Sheets("07-Component").Range("B" & Rows.Count).End(xlUp).Row

With Sheets("JCX").Range("H2:H" & LastRow)
    .Formula = "=IFERROR(VLOOKUP('07-Component'!B2, '04-Space'!A:B, 2,),""Can't find!"")"
    .Value = .Value
End With
 
Upvote 0
Ended up doing this. Only took another glance at the syntax :P

I forgot the quotes around the values in the Range section. Works like a champ.

Code:
Do
    Sheets("JCX").Cells(TagRowCounter, 8).Value = Application.VLookup(Sheets("07-Component").Cells(TagRowCounter, 2), Sheets("04-Space").Range("A:B"), 2, 0)
    TagRowCounter = TagRowCounter + 1
    
Loop Until Sheets("07-Component").Cells(TagRowCounter, 2) = False
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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