VBA code to reference worksheet second from the end

kwagner1222

New Member
Joined
Aug 22, 2024
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
I am trying to add a vlookup code to a cell and have to reference the worksheet to the left/second to last sheet in the workbook. The name will change since it's a date, not always the date
prior because of the weekend. Some things I tried are below, none worked ...

Dim sh As Worksheet
Set sh = Sheets(Sheets.Count - 1)

1) Range("Z6").Formula = "=VLOOKUP(B2,'[LISR Formatting_Macro - WIP.xlsm]sh'!$B$6:$AB$150,26,FALSE)"

2) Range("Z6").Formula = "=VLOOKUP(B2,Sheets(sh)!$B$6:$AB$150,26,FALSE)"

3) Range("Z6").Value = WorksheetFunction.VLookup(Range(B2), Workbooks("LISR Formatting_Macro - WIP.xlsm").Sheets("sh").Range("B6:AB150"), 26, False)

4) Range("Z6").Value = Application.VLookup(B2, Sheets(sh).Range("B6:AB150"), 26, False)

5) Range("Z6").Formula = "=VLOOKUP(B2,Sheets(sh)!$B$6:$AB$150,26,FALSE)"

Worksheets: I add one to the end with the current date and reference the day before/worksheet to the left. One is added each workday.
1724354705500.png


Any ideas on how to get this vlookup formula to work and reference the tab to the left? Thank you!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,224,737
Messages
6,180,648
Members
452,992
Latest member
TokugawaIesuma

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top