VBA Code to Select Worksheet Based on User-Selected Cell Value

AspiringAutomater

New Member
Joined
Jul 31, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello,
Long-time googler, first time poster here... I am trying to write brief code to allow me to select a cell, and then to select the worksheet whose name is equal to the cell value. Below is my attempted code and I get hung up on the "NewFrozenSheet = Range(c).Value" line. This code works if I hard code "c" to the cell reference (e.g., "A1"...rendering "c" irrelevant), but I would like it to remain a variable in the code. Appreciate whatever help anyone can offer, and thank you in advance!

Sub Monthly()

' Monthly Macro

Sheets("Consolidated Data").Select

Dim c As Range
Set c = Application.InputBox(prompt:="Select Last Sheet Ref to Freeze", Type:=8)

Dim NewFrozenSheet As String
NewFrozenSheet = Range(c).Value
Sheets(NewFrozenSheet).Activate

End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Nevermind...I found a solution.

Dim c As Range
Set c = Application.InputBox(prompt:="Select Last Sheet Ref to Freeze", Type:=8)

c.Activate

Dim NewFrozenSheet As String
NewFrozenSheet = ActiveCell.Value
Sheets(NewFrozenSheet).Activate

I think the main holdup was that I had to reverse the order of the line of code which was breaking.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,951
Messages
6,122,442
Members
449,083
Latest member
Ava19

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