Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default renaming tabs based on a on a worksheet

HI
This is a piece of code written by Dave Peterson, it works perfect for
my needs.

Option Explicit
Sub testme01()
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
With wks
On Error Resume Next
..Name = .Range("b4").Text
If Err.Number < 0 Then
MsgBox .Name & " was not renamed"
Err.Clear
End If
On Error GoTo 0
End With
Next wks
End Sub



However what I would like to also do would be to delete a worksheet if
the is no value in cell b4.

Many thanks for any suggestions.

Thanks
Eddie

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default renaming tabs based on a on a worksheet

Hi
You can change your sub to this. Displayalerts suppresses the "are you
sure?" message when the sheet is deleted. The Trim command is there
incase your B4 cell has a space or other none printing character in
it.
I took the On Error code out of the loop too - no need to call it each
time.
regards
Paul

Option Explicit
Sub testme02()
Dim wks As Worksheet
On Error Resume Next
For Each wks In ActiveWorkbook.Worksheets
With wks
If Trim(.Range("b4").Text) = "" Then
Application.DisplayAlerts = False
.Delete
Application.DisplayAlerts = True
Else
.Name = .Range("b4").Text
If Err.Number < 0 Then
MsgBox .Name & " was not renamed"
Err.Clear
End If
End If
End With
Next wks
On Error GoTo 0
End Sub



On May 10, 1:55*am, webels wrote:
HI
This is a piece of code written by Dave Peterson, it works perfect for
my needs.

Option Explicit
Sub testme01()
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
With wks
On Error Resume Next
.Name = .Range("b4").Text
If Err.Number < 0 Then
MsgBox .Name & " was not renamed"
Err.Clear
End If
On Error GoTo 0
End With
Next wks
End Sub

However what I would like to also do would be to delete a worksheet if
the is no value in cell b4.

Many thanks for any suggestions.

Thanks
Eddie


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default renaming tabs based on a on a worksheet

On May 10, 9:03*am, Paul Robinson
wrote:
Hi
You can change your sub to this. Displayalerts suppresses the "are you
sure?" message when the sheet is deleted. The Trim command is there
incase your B4 cell has a space or other none printing character in
it.
I took the On Error code out of the loop too - no need to call it each
time.
regards
Paul

Option Explicit
Sub testme02()
Dim wks As Worksheet
On Error Resume Next
For Each wks In ActiveWorkbook.Worksheets
With wks
If Trim(.Range("b4").Text) = "" Then
Application.DisplayAlerts = False
* * .Delete
Application.DisplayAlerts = True
Else
* * .Name = .Range("b4").Text
* If Err.Number < 0 Then
* * MsgBox .Name & " was not renamed"
* * Err.Clear
* End If
End If
End With
Next wks
On Error GoTo 0
End Sub

On May 10, 1:55*am, webels wrote:







HI
This is a piece of code written by Dave Peterson, it works perfect for
my needs.


Option Explicit
Sub testme01()
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
With wks
On Error Resume Next
.Name = .Range("b4").Text
If Err.Number < 0 Then
MsgBox .Name & " was not renamed"
Err.Clear
End If
On Error GoTo 0
End With
Next wks
End Sub


However what I would like to also do would be to delete a worksheet if
the is no value in cell b4.


Many thanks for any suggestions.


Thanks
Eddie


Very neat Paul
Works a treat
Thanks
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I name Worksheet Tabs based on some king of reference? Gord Dibben Excel Worksheet Functions 4 August 1st 07 10:52 PM
Renaming Tabs Lakebum Excel Discussion (Misc queries) 3 December 26th 06 09:43 PM
renaming worksheet tabs calibronco Excel Discussion (Misc queries) 7 November 26th 05 01:02 AM
Renaming Tabs ANDY73 Excel Discussion (Misc queries) 5 July 28th 05 09:42 AM
Renaming worksheet tabs Dave[_31_] Excel Programming 4 October 14th 03 04:38 PM


All times are GMT +1. The time now is 07:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"