I have set the following reference for different workbooks at the start of my macro which is working fine as I swop between different workbooks. (the references are commented out as they are in the option explicit area, but I have shown them for information
I have moved between workbooks using the variations of the following code
However I am now trying to do a vlookup from one spreadsheet to another and cannot get the reference to work. I normally use the following format when i know the workbook name
but I have tried adapting the code to look at the workbook now referenced as rp but I am getting error 1004 so I know it cannot see the workbook at all. I have tried putting brackets in various places but to no avail and have included below I couple that I have tried.
attempt 1
attempt 2
If anyone can point me in the right direction I would be most grateful
Code:
'Dim ad As Workbook 'address file suffix HDR
'Dim rp As Workbook 'ratio pack suffix PKS
'Dim sd As Workbook 'main data file DTL
'Call WorkbookName
'Dim od As String
od = InputBox(Prompt:="Enter the Order Number", _
Title:="Order Number", Default:="eg JN00104")
If od = "eg JN00104" Or _
od = vbNullString Then
Exit Sub
Else
End If
ad = od & "." & "HDR"
rp = od & "." & "PKS"
md = od & "." & "DTL"
I have moved between workbooks using the variations of the following code
Code:
Windows(md).Activate
Workbooks("JaneNormanMacros.xls").Worksheets("Main Range IO").Range("A1:w24").Copy
Workbooks(ad).Worksheets("sheet1").Range("A1").PasteSpecial Paste:=xlAll
However I am now trying to do a vlookup from one spreadsheet to another and cannot get the reference to work. I normally use the following format when i know the workbook name
Code:
=VLOOKUP(RC[-1],'[lookupfiles.xls]LLoyd TopMan'!burtoneuro,2,FALSE)
attempt 1
Code:
Range("B16").FormulaR1C1 = "=VLOOKUP(R[5]C[1],'[workbooks(rp)]Formatted File' !ratiopack,5,FALSE)"
Code:
Range("B16").FormulaR1C1 = "=VLOOKUP(R[5]C[1],'[rp]Formatted File' !ratiopack,5,FALSE)"
If anyone can point me in the right direction I would be most grateful