I’m not very good at VBA for excel, but seem to muddle through most things. My current issue with VBA is:
I’m trying to reference a workbook in a vlookup formula using VBA. The workbook and worksheet will change every quarter (no naming convention). Here's the following code:
PreviousSheetName = ActiveWorkbook.Name
PreviousSheet = ActiveSheet.Name
msg = MsgBox("Select your approved Tool List", vbOKOnly)
CurrentSheetName = Application.GetOpenFilename("Excel Files *.XLS,*.xls")
Workbooks.Open (CurrentSheetName)
CurrentSheetName = ActiveWorkbook.Name
CurrentSheet = ActiveSheet.Name
Range("A4").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-12],'[" & PreviousSheetName & "]" & PreviousSheet & !P:AA,12,0)"
In Excel it gives me a #NAME? error, but if I click into the cell it will actually give me a value.
Please help. Tell me what I’m doing wrong.
Thanks,
Heidi
I’m trying to reference a workbook in a vlookup formula using VBA. The workbook and worksheet will change every quarter (no naming convention). Here's the following code:
PreviousSheetName = ActiveWorkbook.Name
PreviousSheet = ActiveSheet.Name
msg = MsgBox("Select your approved Tool List", vbOKOnly)
CurrentSheetName = Application.GetOpenFilename("Excel Files *.XLS,*.xls")
Workbooks.Open (CurrentSheetName)
CurrentSheetName = ActiveWorkbook.Name
CurrentSheet = ActiveSheet.Name
Range("A4").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-12],'[" & PreviousSheetName & "]" & PreviousSheet & !P:AA,12,0)"
In Excel it gives me a #NAME? error, but if I click into the cell it will actually give me a value.
Please help. Tell me what I’m doing wrong.
Thanks,
Heidi