I have a macro in Workbook 1. the workbook is called "Detail Load Template FY15 VCA 3270100 revised.xls" that looks at a worksheet and exports the data to a txt file.
On the txt file I need to include some headings. One of the headings is a company code that needs to be found from a table back on workbook 1
The below code works and the vlookup places the cocode in the cell. But I want the workbook reference below can change when the macro is put in different named workbooks. So I need the Workbook name reference to be dynamic depending on the name of the xls spreadsheet it is operating in.
I was trying the below that gives me the Workbook name correctly but not sure how I can work this into the Vlookup sum.
naturally below does not work. So how do I get the result of Getbook into the vlookup ? can I have the Getbook insert its result to a cell and then have vlookup reference that cell?
On the txt file I need to include some headings. One of the headings is a company code that needs to be found from a table back on workbook 1
The below code works and the vlookup places the cocode in the cell. But I want the workbook reference below can change when the macro is put in different named workbooks. So I need the Workbook name reference to be dynamic depending on the name of the xls spreadsheet it is operating in.
Code:
Dim strCoCode As Variant
strCoCode = "=VLOOKUP(b5,'[Detail Load Template FY15 VCA 3270100 revised.xls]ProfitCentres'!A:D,3,0)" 'look up strProfitCenter worksheet for CoCode and offset 3
Cells(1, 4).Value = strCoCode ' Places the CoCode in cell D1.
I was trying the below that gives me the Workbook name correctly but not sure how I can work this into the Vlookup sum.
Code:
Function getbook() As String
getbook = ActiveWorkbook.Name
MsgBox "BookName is : $ " & getbook
End Function
Code:
strCoCode = "=VLOOKUP(b5,'GetBook & ProfitCentres'!A:D,3,0)"
naturally below does not work. So how do I get the result of Getbook into the vlookup ? can I have the Getbook insert its result to a cell and then have vlookup reference that cell?