jbennett01
New Member
- Joined
- Apr 25, 2018
- Messages
- 12
- Office Version
- 2016
- Platform
- Windows
I need to dynamically add sheets to my workbook and then add VLookup formulas to my main sheet that reference the newly added sheets. I did this easily with a static name but doing it dynamically has eluded me. I have reviewed an answer to this question on this forum and could not get that to work. I found a solution on the MicroSoft forum and that functions.
What I started with:
This tried to open a new file. From the MS forum I tried changing the formula line to this.
That seems to work but I am concerned how it will function as I modify the code to add several more sheets to the workbook. I do not really understand the 'R1C1' or any of those cell references, such as C[-2] or C[10].
Is this the best way or is there a better approach to this?
Thank you.
What I started with:
VBA Code:
Dim strNewSheetName As String
strNewSheetName = "Upload 2023-1-2"
ActiveCell.FormulaR1C1 = "=VLOOKUP(C[-2],strNewSheetName!C[10],1)"
This tried to open a new file. From the MS forum I tried changing the formula line to this.
VBA Code:
ActiveCell.FormulaR1C1 = "=+VLOOKUP(C[-2],'" & strNewSheetName & "'!C[10],1)"
That seems to work but I am concerned how it will function as I modify the code to add several more sheets to the workbook. I do not really understand the 'R1C1' or any of those cell references, such as C[-2] or C[10].
Is this the best way or is there a better approach to this?
Thank you.