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

Can you perform data validation for the worksheets within a work book?
For example, if I type in a cell a worksheet name, can excel tell me if
the name I typed in matches a worksheet name in the workbook? If so
How?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Data Validation

If you had that list of worksheet names somewhere, you could use that in the
data|validation rules.

Or you could use a macro (worksheet_change event) to do the validation, too.

This checks to see if there is a worksheet with the name you typed in A1.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim wks As Worksheet

If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("a1")) Is Nothing Then
Exit Sub
End If

Set wks = Nothing
On Error Resume Next
Set wks = Me.Parent.Worksheets(CStr(Target.Value))
On Error GoTo 0

On Error GoTo errHandler:

If wks Is Nothing Then
'invalid name
MsgBox "Not valid"
With Application
.EnableEvents = False
.Undo 'set it back
End With
End If

errHandler:
Application.EnableEvents = True

End Sub

Rightclick on the worksheet tab that should have this behavior. Select view
code and paste that code into the code window.

Then back to excel to test it out.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

If you want to read more about these kinds of events:

Chip Pearson's site:
http://www.cpearson.com/excel/events.htm

David McRitchie's site:
http://www.mvps.org/dmcritchie/excel/event.htm

cvach wrote:

Can you perform data validation for the worksheets within a work book?
For example, if I type in a cell a worksheet name, can excel tell me if
the name I typed in matches a worksheet name in the workbook? If so
How?


--

Dave Peterson
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
custom data validation on cells with data validation values AKrobbins Excel Worksheet Functions 2 June 21st 11 04:20 PM
Validation Data using Validation Table cell range..... Dermot Excel Discussion (Misc queries) 16 January 5th 10 09:35 PM
data validation invalid in dynamic validation list ilia Excel Discussion (Misc queries) 0 November 7th 06 12:54 PM
data validation invalid in dynamic validation list ilia Excel Worksheet Functions 0 November 7th 06 12:54 PM
Data validation with validation lists and combo boxs Keith Excel Discussion (Misc queries) 1 October 12th 06 11:08 AM


All times are GMT +1. The time now is 01:54 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"