how to select current sheet tab

G

Guest

I simply want to copy a cell and paste it into the worksheet tab to name the
sheet what is in the cell. When I record a macro, it just trys to select the
same sheet I selected when recording the macro. I was wandering how to get
the macro to select the current sheet. here is the recorded macro:

Range("A1").Select
Selection.Copy
Sheets("55555").Select
Sheets("55555").Name = "1 06"
Range("B11").Select
Application.CutCopyMode = False
Sheets("Sheet2").Select
End Sub

Thank You for your help!
 
B

Bob Phillips

Do you mean

Activesheet.Name = Range("A1").value

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
D

Don Guillett

From the sheet with a1 wihtout selections or copying

sub namesht()'
sheets("55555").name=range("a1").value
end sub
 
G

Guest

Ok thank you that works great! Now could you tell me the code to go to the
next sheet with a loop? Like change the name then go to the next sheet and
change it, and so on 26 times? I was trying something like this but it wasn't
working:

Sub namesht() '
Dim i As Long
For i = 1 To 26
Sheets(i).Name = Range("a1").Value
Next i
End Sub

thank you!
 
G

Guest

Give this a whirl...

Sub namesht() '
Dim i As Long
For i = 1 To 26
Sheets(i).Name = Sheets(i).Range("a1").Value
Next i
End Sub
 
B

Bob Phillips

Might as well count them Jin

Sub namesht()
Dim i As Long
For i = 1 To Activeworkbook.Worksheets.Count
Worksheets(i).Name = Worksheets(i).Range("a1").Value
Next i
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
G

Guest

Assuming that the OP is doing all of the sheets then I would agree... But
then I would use a worksheet object (just because I like to be fancy)...

Sub namesht()
Dim wks As worksheet
for each wks in worksheets
wks.Name = wks.Range("a1").Value
Next wks
End Sub
 
G

Gord Dibben

Knox

Sub wsname()
Dim WS As Worksheet
For Each WS In ActiveWorkbook.Worksheets
WS.Name = WS.Cells(1, 1).Value
Next WS
End Sub


Gord Dibben MS Excel MVP
 
B

Bob Phillips

I'm never going to knock fancy <bg>

Bob



Jim Thomlinson said:
Assuming that the OP is doing all of the sheets then I would agree... But
then I would use a worksheet object (just because I like to be fancy)...

Sub namesht()
Dim wks As worksheet
for each wks in worksheets
wks.Name = wks.Range("a1").Value
Next wks
End Sub
 
G

Guest

Look... Gord is Fancy too... It must be a British Columbia thing. Perhaps
something in the salt air... <bg>
 
G

Guest

Thanks to all of you I learned a lot! For my purposes this worked:

Dim i As Long
For i = 1 To 26
Sheets(i).Name = Sheets(i).Range("a1").Value
Next i

thanx again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top