Renaming Worksheets Using Reference

edhead4

New Member
Joined
Feb 25, 2005
Messages
4
I know there are a few posts on this but from the one's I've seen, this is unique...

I have a database that I'm running reports from. I am trying to create a macro that will create a new sheet and name it based on a new value in the new sheet. Here's what it will do:

1. Copy data from current sheet
2. Create a new sheet and paste the data into it
3. change the cell linking the sheet to my master database so that the new sheet shows the new values
4. Rename the new sheet based onthe new value in the linking cell.

I'm okay until the renaming part. I can't get the macro to link to the newly created sheet in order to pick the right value. My macro is in shambles right now, otherwise I would paste it. Any help is greatly appreciated!

thanx!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Private Sub Worksheet_Change(ByVal Target As Range)
'Sheet Module code, like: Sheet1!
Dim myAddress As String

myAddress = "$B$3"

If Target.Address = myAddress And Range("B3").Value <> "" Then
Range("B3").Select
ActiveSheet.Name = Range("B3").Value
End If
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'ThisWorkbook module code!
Dim myAddress As String
Dim myName As String

myAddress = "$B$3"

If Worksheets(1).Range("B3").Value <> "" Then
Worksheets(1).Range("B3").Select
myName = Selection.Value
Worksheets(1).Name = myName
End If
End Sub


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'ThisWorkbook module code!
Dim myAddress As String
Dim myName As String

myAddress = "$B$3"

If Worksheets(1).Range("B3").Value <> "" Then
Worksheets(1).Range("B3").Select
myName = Selection.Value
Worksheets(1).Name = myName
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,054
Latest member
juliecooper255

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