Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default Validation question

I have worksheet_calculate even that changes the name of the sheet tab
depending on cell D4 wich contains "OF_"&B4
Is there any way to set validation on cell B4 so that it is not possible to
insert symbols that are not accepted as sheet names as - * etc. or is it
possible to prevent this in the event code. The code is as follows

Private Sub Worksheet_Calculate()
Me.Name = Range("D4")
End Sub

Thanks for any help

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Validation question

You can put in about any valid formula in data validation, so if you come up
with a formula which checks for all the invalid characters, then you could
us validation. In you event, you would have to just remove any invalid
characters or clear the cell and not rename the sheet or something like
that. I am sure you will receive other ideas as well.

--
regards,
Tom Ogilvy

"Adam" wrote in message
...
I have worksheet_calculate even that changes the name of the sheet tab
depending on cell D4 wich contains "OF_"&B4
Is there any way to set validation on cell B4 so that it is not possible

to
insert symbols that are not accepted as sheet names as - * etc. or is it
possible to prevent this in the event code. The code is as follows

Private Sub Worksheet_Calculate()
Me.Name = Range("D4")
End Sub

Thanks for any help



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Validation question

Hi Adam,

The following is slightly modified from something I use.

Best Regards,
Walt Weber

'This part in the Sheet Obect Code
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("B4").Address Then _
Call NameSheet
End Sub

'This part in a Module
'Call this from the Worksheet Change routine.
Sub NameSheet()
Dim ChNo As Integer, X As String, Y As String
On Error GoTo NameSheetERROR
Application.EnableCancelKey = False
X = ActiveSheet.Range("D4").Value
Y = ""

'Remove Special Characters
'I think I remember this part was in a Debra Dalgleish response.
For ChNo = 1 To Len(X)
If Mid(X, ChNo, 1) Like "[A-Za-z0-9]" Then
Y = Y & Mid(X, ChNo, 1)
End If
Next

'Optionally limit the name to 12 characters.
Y = Left(Y, 12)

'Trap any worksheet name duplicates
For Each WS In ThisWorkbook.Worksheets
If UCase(WS.Name) = UCase(Y) Then
MsgBox "That name resolves to one already in use." _
& Chr(13) & "Try changing it please."
Exit Sub
End If
Next

ActiveSheet.Name = Y
Exit Sub
NameSheetERROR:
MsgBox "Error in NameSheet routine. -- " & Error()
End Sub


"Adam" wrote:

I have worksheet_calculate even that changes the name of the sheet tab
depending on cell D4 wich contains "OF_"&B4
Is there any way to set validation on cell B4 so that it is not possible to
insert symbols that are not accepted as sheet names as - * etc. or is it
possible to prevent this in the event code. The code is as follows

Private Sub Worksheet_Calculate()
Me.Name = Range("D4")
End Sub

Thanks for any help

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
Validation Question KLock Excel Discussion (Misc queries) 2 December 3rd 08 04:23 PM
Validation question ComicFly Excel Worksheet Functions 3 August 6th 08 05:21 AM
Validation Question RJ Swain Excel Worksheet Functions 8 February 10th 08 10:49 PM
validation question G Excel Discussion (Misc queries) 12 January 24th 06 10:55 PM
Validation Question....Can this be done? harpscardiff Excel Discussion (Misc queries) 2 January 11th 06 05:15 PM


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

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

About Us

"It's about Microsoft Excel"