Vlookup with sheet names stored in array

Syaza Azman

New Member
Joined
May 16, 2018
Messages
3
Hi,
i'm trying to vlookup some comments from different workbooks but with the same name.
so i stored the names in an array.

i got 2 problems here,

1. first vlookup runs without an error but doesnt return any result
2. second vlookup gives error 1004; Application-defined or object deifned error

here's the code

Code:
For Each TabName In Array("report", "Pending", "Created")
        
        On Error GoTo NextTabName8
                      
            If TabName = "report" Then
            
                VLatCell = "T3"
                AutoFillIndicator = "R3"
                
                Windows("Work_Order_Report__Weekly_Repo.xlsx").Activate
                Sheets(TabName).Select
                Range("T1").Value = TabName
                Range(VLatCell).Select
                ActiveCell.FormulaR1C1 = _
                    "=VLOOKUP(RC[-5],'[Work Order Report - 8 Week.xlsx]" & "TabName" & "'!C15:C20,6,0)"
                    
                Range(AutoFillIndicator).Select
                Selection.End(xlDown).Select
                ActiveCell.Offset(0, 2).Select
                Range(Selection, "T3").Select
                Selection.FillDown
            
            Else
            
            
                VLatCell = "S2"
                AutoFillIndicator = "R2"
                
                        
                Windows("Work_Order_Report__Weekly_Repo.xlsx").Activate
                Sheets(TabName).Select
                Range(VLatCell).Select
                ActiveCell.FormulaR1C1 = _
                    "=VLOOKUP(RC[-4],'[Work Order Report - 8 Week.xlsx]" & "TabName" & "'!C15:C19,5,0)"
                    
                Range(AutoFillIndicator).Select
                Selection.End(xlDown).Select
                ActiveCell.Offset(0, 2).Select
                Range(Selection, "S2").Select
                Selection.FillDown
        
            End If


NextTabName8:
Next TabName
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Nevermind,
i've got it.



ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-4],'[Work Order Report - 8 Week.xlsx]" & "TabName" & "'!C15:C19,5,0)"


is supposed to be




ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-4],'[Work Order Report - 8 Week.xlsx]" & TabName & "'!C15:C19,5,0)"

Hi,
i'm trying to vlookup some comments from different workbooks but with the same name.
so i stored the names in an array.

i got 2 problems here,

1. first vlookup runs without an error but doesnt return any result
2. second vlookup gives error 1004; Application-defined or object deifned error

here's the code

Code:
For Each TabName In Array("report", "Pending", "Created")
        
        On Error GoTo NextTabName8
                      
            If TabName = "report" Then
            
                VLatCell = "T3"
                AutoFillIndicator = "R3"
                
                Windows("Work_Order_Report__Weekly_Repo.xlsx").Activate
                Sheets(TabName).Select
                Range("T1").Value = TabName
                Range(VLatCell).Select
                ActiveCell.FormulaR1C1 = _
                    "=VLOOKUP(RC[-5],'[Work Order Report - 8 Week.xlsx]" & "TabName" & "'!C15:C20,6,0)"
                    
                Range(AutoFillIndicator).Select
                Selection.End(xlDown).Select
                ActiveCell.Offset(0, 2).Select
                Range(Selection, "T3").Select
                Selection.FillDown
            
            Else
            
            
                VLatCell = "S2"
                AutoFillIndicator = "R2"
                
                        
                Windows("Work_Order_Report__Weekly_Repo.xlsx").Activate
                Sheets(TabName).Select
                Range(VLatCell).Select
                ActiveCell.FormulaR1C1 = _
                    "=VLOOKUP(RC[-4],'[Work Order Report - 8 Week.xlsx]" & "TabName" & "'!C15:C19,5,0)"
                    
                Range(AutoFillIndicator).Select
                Selection.End(xlDown).Select
                ActiveCell.Offset(0, 2).Select
                Range(Selection, "S2").Select
                Selection.FillDown
        
            End If


NextTabName8:
Next TabName
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,679
Members
449,463
Latest member
Jojomen56

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