ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Textbox value - rename worksheet with (https://www.excelbanter.com/excel-programming/407588-textbox-value-rename-worksheet.html)

LRay67

Textbox value - rename worksheet with
 
I have 10 tabs that I will need to rename from a textbox (not the range in
the code below). The following code has to be ran first, then backtrack to
rename the appropriate tabs to the value in the textbox. Anyone have any
ideas?

Range("P5:R5").Copy
For sh = 2 To Sheets.Count
If Sheets(sh).Name Like ("Request*") Then
ActiveSheet.Paste Destination:=Sheets(sh).Range("P5:R5")
End If
Next
End Sub

Mike

Textbox value - rename worksheet with
 
Dim wsName As String
Dim WS_Count As Integer
Dim i As Integer
WS_Count = ActiveWorkbook.Worksheets.Count
' Begin the loop.
For i = 1 To WS_Count
wsName = Textbox1.value & i
On Error Resume Next
ActiveWorkbook.Worksheets(i).Name = & wsName
Next i

"LRay67" wrote:

I have 10 tabs that I will need to rename from a textbox (not the range in
the code below). The following code has to be ran first, then backtrack to
rename the appropriate tabs to the value in the textbox. Anyone have any
ideas?

Range("P5:R5").Copy
For sh = 2 To Sheets.Count
If Sheets(sh).Name Like ("Request*") Then
ActiveSheet.Paste Destination:=Sheets(sh).Range("P5:R5")
End If
Next
End Sub


LRay67

Textbox value - rename worksheet with
 
Mike,

I tried the code below, but it is not working. The
ActiveWorkbook.Worksheets(i).Name = & wsName (code) comes up in red.
Another co-worker & I have been trying to figure this out, but are unable to.
Any suggestions??

"Mike" wrote:

Dim wsName As String
Dim WS_Count As Integer
Dim i As Integer
WS_Count = ActiveWorkbook.Worksheets.Count
' Begin the loop.
For i = 1 To WS_Count
wsName = Textbox1.value & i
On Error Resume Next
ActiveWorkbook.Worksheets(i).Name = & wsName
Next i

"LRay67" wrote:

I have 10 tabs that I will need to rename from a textbox (not the range in
the code below). The following code has to be ran first, then backtrack to
rename the appropriate tabs to the value in the textbox. Anyone have any
ideas?

Range("P5:R5").Copy
For sh = 2 To Sheets.Count
If Sheets(sh).Name Like ("Request*") Then
ActiveSheet.Paste Destination:=Sheets(sh).Range("P5:R5")
End If
Next
End Sub


Mike

Textbox value - rename worksheet with
 
Try this
Sub WorksheetLoop()
Dim wsName As String
Dim WS_Count As Integer
Dim i As Integer
WS_Count = _
ActiveWorkbook.Worksheets.Count
' Begin the loop.
For i = 1 To WS_Count
wsName = "wk" & i
On Error Resume Next
ActiveWorkbook.Worksheets(i).Name = _
wsName
Next i
End Sub

"LRay67" wrote:

Mike,

I tried the code below, but it is not working. The
ActiveWorkbook.Worksheets(i).Name = & wsName (code) comes up in red.
Another co-worker & I have been trying to figure this out, but are unable to.
Any suggestions??

"Mike" wrote:

Dim wsName As String
Dim WS_Count As Integer
Dim i As Integer
WS_Count = ActiveWorkbook.Worksheets.Count
' Begin the loop.
For i = 1 To WS_Count
wsName = Textbox1.value & i
On Error Resume Next
ActiveWorkbook.Worksheets(i).Name = & wsName
Next i

"LRay67" wrote:

I have 10 tabs that I will need to rename from a textbox (not the range in
the code below). The following code has to be ran first, then backtrack to
rename the appropriate tabs to the value in the textbox. Anyone have any
ideas?

Range("P5:R5").Copy
For sh = 2 To Sheets.Count
If Sheets(sh).Name Like ("Request*") Then
ActiveSheet.Paste Destination:=Sheets(sh).Range("P5:R5")
End If
Next
End Sub



All times are GMT +1. The time now is 11:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com