Refering to a Sheet that has been Named using InputBox

Newbie74

New Member
Joined
Feb 6, 2014
Messages
10
Hi,

I am stuck on a piece of code that I can't figure out. If I have just inserted and named a new sheet using VBA how can I refer to this new sheet further down in my code? So far I have this...

Sub VlookupDivStocks()




Sheets.Add.Name = InputBox("What would you like to Call this sheet?")




Sheets("2013").Activate
Range("A1").EntireRow.Copy

Sheets(".........").activate <<<<<<what should="" go="" here="" to="" refer="" the="" new="" worksheet="" that="" was="" added="" earlier?
what should go here to refer to the newly inserted sheet?
range("a1").paste






End Sub</what>
 
Last edited:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Seperate the line into 2 lines, and assign the result of the inputbox to a variable...

MyVaraible = InputBox(....)
Sheets.Add.Name = MyVariable

Sheets(MyVariable).Activate
 
Upvote 0
In general, when you add a sheet it becomes the ActiveSheet. You can take advantage of that to get a reference to it. e.g.

Code:
Sheets.Add.Name = InputBox("What would you like to Call this sheet?")
Set NewSht = ActiveSheet

In this case though, I'd use Jonmo1's method.
 
Upvote 0
Or
Code:
Dim newSheet as Worksheet
Dim newName as String

newName = InputBox("Name please")

Set newSheet = ThisWorkbook.WorkSheets.Add

newSheet.Name = newName

newSheet.Activate
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,855
Members
449,096
Latest member
Erald

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