VB - Ask User to Select Sheet Then Input That Sheet Name Into Formulas

Cat129

Board Regular
Joined
Oct 20, 2012
Messages
96
Hey,

I have an existing document with information in, each sheet is named by date that it gets from a cell within that sheet.

I have written code to update from a text file, but where I am stuck is I need the user to select what sheet they want the lookups to work from. I can't add the sheet name into the vb because it will be forever changing.

I found this from googling but dont understand how I implement this into my code

Code:
Dim desiredSheetName As String
desiredSheetName = Application.InputBox("Select Any Cell From The Sheet You Want To Lookup", "Sheet Lookup", Type:=8).Worksheet.Name
Debug.Print desiredSheetName

What I basically want is to add the sheet name the user defines into this code

Code:
"=IFNA(IFNA(IF(VLOOKUP(RC[-2],'30th May'!C[-2],1,FALSE)=RC[-2],""No Change"",""""),IF(VLOOKUP(RC[-1],'30th May'!C[-1],1,FALSE)='Tue Jun  4'!RC[-1],""Revision Change"","""")),""New UA"")"

Help greatly appreciated
Cat
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hey,

Your code is referencing 2 different worksheets currently, do you want both to point at the worksheet defined by the user via the input box?
 
Last edited by a moderator:
Upvote 0
If it's the 30th May sheet you want to be a variable try
Code:
   Dim ShtNm As String
   ShtNm = Application.InputBox("Select Any Cell From The Sheet You Want To Lookup", "Sheet Lookup", Type:=8).Worksheet.name
   Range("A1:A20").FormulaR1C1 = "=IFNA(IFNA(IF(VLOOKUP(RC[-2],'" & ShtNm & "'!C[-2],1,FALSE)=RC[-2],""No Change"",""""),IF(VLOOKUP(RC[-1],'" & ShtNm & "'!C[-1],1,FALSE)='Tue Jun  4'!RC[-1],""Revision Change"","""")),""New UA"")"
 
Upvote 0
If it's the 30th May sheet you want to be a variable try
Code:
   Dim ShtNm As String
   ShtNm = Application.InputBox("Select Any Cell From The Sheet You Want To Lookup", "Sheet Lookup", Type:=8).Worksheet.name
   Range("A1:A20").FormulaR1C1 = "=IFNA(IFNA(IF(VLOOKUP(RC[-2],'" & ShtNm & "'!C[-2],1,FALSE)=RC[-2],""No Change"",""""),IF(VLOOKUP(RC[-1],'" & ShtNm & "'!C[-1],1,FALSE)='Tue Jun  4'!RC[-1],""Revision Change"","""")),""New UA"")"

Perfection! Thank You
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,483
Members
448,967
Latest member
visheshkotha

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