This code goes in the worksheet code module that you want to click the
cells in, i have commented the code so you understand it, it can
probably be done a lot smarter but this works and you can understand it:
Code:
--------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Sh As Worksheet
'don't show changes until operation complete
Application.ScreenUpdating = False
'if more than one cell selected exit sub
If Target.Cells.Count 1 Then Exit Sub
'if we are not clicking in column 1 exit sub
If Target.Column < 1 Then Exit Sub
'On Error GoTo Nxt
'to leave the copy in same workbook remove ' before "After"
Sheets(Target.Value).Copy After:=Sheets(Sheets.Count)
'check if sheet exists
For Each Sh In Sheets
If Sh.Name = ActiveSheet.Range("A1").Value Then
'don't show alerts for deletion
Application.DisplayAlerts = False
ActiveSheet.Delete
'turn alerts back on
Application.DisplayAlerts = True
GoTo Nxt1
End If
Next Sh
'rename the copied sheet to the contents of A1 of the new sheet
ActiveSheet.Name = ActiveSheet.Range("A1").Value
GoTo SubEnd
Nxt1:
MsgBox "Sheet already exists, it will not be created!"
GoTo SubEnd
Nxt:
MsgBox "No sheet found of that name"
SubEnd:
'show changes
Application.ScreenUpdating = False
'back to original sheet
Me.Activate
End Sub
--------------------
*How to Save a Worksheet Event Macro*
1. *Copy* the macro using *CTRL+C* keys.
2. Open your Workbook and *Right Click* on the *Worksheet's Name Tab*
for the Worksheet the macro will run on.
3. *Left Click* on *View Code* in the pop up menu.
4. *Paste* the macro code using *CTRL+V*
5. Make any custom changes to the macro if needed at this time.
6. *Save* the macro in your Workbook using *CTRL+S*
Susan Schmid;381016 Wrote:
Hi Simon,
I am the former co-worker of Al with the question. I reviewed your
answers.
The 1st answer that is not using VBA maybe be misunderstood. I want to
use
the contents of a cell i.e, 200904 to be used to find the worksheet
name
200904 to be selected. Then, copy this '200904' sheet and rename this
copied
worksheet using another cell's contents, i.e., 200905.
Thanks,
Susan
"Simon Lloyd" wrote:
Alan Sexter;379826 Wrote:
I am a quantitative analyst who is the leader of our department's
Excel
users
group (Multi-Channel Marketing department of Eastbay, Inc. in
Wausau,
Wisconsin). I have a friend who is a former co-worker in my
department,
but
is now a senior credit analyst with a company in Chicago.
If possible, this credit analyst would like to have Excel take the
contents
of a cell in the workbook, and use it to select a worksheet (in
that
same
workbook) that has the same name as the contents or value of that
cell.
This
seems to be a "twist" on the topic of automated worksheet names
that
has
generated several postings. Any help will be greatly appreciated by
both of
us. Thanks for any help that can be provided!If it is going to be a
static name then it can be a hyperlink, otherwise
it would have to be done with VBA........which would you prefer?
--
Simon Lloyd
Regards,
Simon Lloyd
'The Code Cage' ('http://www.thecodecage.com'
(http://www.thecodecage.com/))
------------------------------------------------------------------------
Simon Lloyd's Profile: 'The Code Cage Forums - View Profile: Simon
Lloyd' (http://www.thecodecage.com/forumz/member.php?userid=1)
View this thread: 'Using Cell Contents to Select Worksheet with Same
Name as Cell Con - The Code Cage Forums'
(http://www.thecodecage.com/forumz/sh...d.php?t=106281)
--
Simon Lloyd
Regards,
Simon Lloyd
'The Code Cage' (
http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile:
http://www.thecodecage.com/forumz/member.php?userid=1
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=106281