VBA - Vlook up error - object doesn't support this property or method.

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

Vlookup is not working , getting below error. In my Input file sheet name has Single quotation (Today's File)
I am getting error as application defined or object defined error.

plz help how to fix it. below is attempted code one with recorded which works. Thanks.

VBA Code:
Sub Vlookup()

    Dim data_wbk As Workbook
    Set data_wbk = Workbooks.Open(ThisWorkbook.Worksheets("Sheet1").Range("d3").Value)

    Dim data_sht As Worksheet
    Set data_sht = data_wbk.Worksheets("Today's File")
       
    With ThisWorkbook.Worksheets("Sheet1").Range("b2:b5")
    'changed variables. 'getting error as application defined or object defined error.
    .FormulaR1C1 = "=VLOOKUP(RC[-1],'[" & data_wbk.Name & "]" & data_sht.name & "'!C1:C11,MATCH(""Score"",'[" & data_wbk.Name & "]" & data_sht.Name & "'!R1C1:R1C8,0))"
   
    'Recorded Code which works
    .FormulaR1C1 = "=VLOOKUP(RC[-1],'[Todays''s File .xlsx]Today''s File'!C[-1]:C[11],MATCH(""Score"",'[Todays''s File .xlsx]Today''s File'!R1C1:R1C8,0))"
   
    End With
   
End Sub

Thanks
mg
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Use
VBA Code:
    .FormulaR1C1 = "=VLOOKUP(RC[-1],'[" & Replace(data_wbk.Name, "'", "''") & "]" & Replace(data_sht.Name, "'", "''") & "'!C1:C11,MATCH(""Score"",'[" & Replace(data_wbk.Name, "'", "''") & "]" & Replace(data_sht.Name, "'", "''") & "'!R1C1:R1C8,0))"
 
Upvote 0
even easier if the single quote wasn't in the sheet name :D
 
Upvote 0
Hi Fluff and Mole999.

I tested this code works perfectly with both the situation with quotation and without quotation.

Many many thanks for your help !!! ?



Thanks
mg
 
Upvote 0
Hi Fluff and Mole999.

I tested this code works perfectly with both the situation with quotation and without quotation.

Many many thanks for your help !!! ?



Thanks
mg
Fluffs code will work with both, only replacing the apostrophe if it exists
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,287
Members
448,562
Latest member
Flashbond

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