kntrigirl1908
New Member
- Joined
- Apr 20, 2020
- Messages
- 4
- Office Version
- 2013
- Platform
- Windows
Hello all! How do I reference the listbox value in my vlookup formula?
I have a workbook with several worksheets that will be individually exported and saved as new workbooks with unique file paths and file names. For ease and time, I've created a list box of worksheet names that the user can select. Based on the this selection, a macro will lookup the desired file path and name, export the worksheet, save the new workbook using the vlookup values based on the list box selection.
My data range, FluxWs, includes a list of worksheet names with the proper file path and file name. But I'm stuck on how to reference the listbox value in my vlookup formula. Any suggestions?
Dim destFilePath As String
Dim destFileName As String
'destFilePath = Application.WorksheetFunction.VLookup(listbox value syntax?, Range("FluxWs"), 4, 0)
destFileName = Application.WorksheetFunction.VLookup(list box value syntax?, Range("FluxWs"), 5, 0)
Application.DisplayAlerts = False
ThisWorkbook.Sheets(SheetArray()).Move Before:=Workbooks.Add.Sheets(1)
ActiveWorkbook.Sheets("Sheet1").Delete
Application.ActiveWorkbook.SaveAs Filename:=destFilePath & destFileName, FileFormat:=xlWorkbookNormal
ActiveWorkbook.Close
I have a workbook with several worksheets that will be individually exported and saved as new workbooks with unique file paths and file names. For ease and time, I've created a list box of worksheet names that the user can select. Based on the this selection, a macro will lookup the desired file path and name, export the worksheet, save the new workbook using the vlookup values based on the list box selection.
My data range, FluxWs, includes a list of worksheet names with the proper file path and file name. But I'm stuck on how to reference the listbox value in my vlookup formula. Any suggestions?
Dim destFilePath As String
Dim destFileName As String
'destFilePath = Application.WorksheetFunction.VLookup(listbox value syntax?, Range("FluxWs"), 4, 0)
destFileName = Application.WorksheetFunction.VLookup(list box value syntax?, Range("FluxWs"), 5, 0)
Application.DisplayAlerts = False
ThisWorkbook.Sheets(SheetArray()).Move Before:=Workbooks.Add.Sheets(1)
ActiveWorkbook.Sheets("Sheet1").Delete
Application.ActiveWorkbook.SaveAs Filename:=destFilePath & destFileName, FileFormat:=xlWorkbookNormal
ActiveWorkbook.Close