Mega Code Archive

 
Categories / VisualBasic Script / Excel
 

Validation with a Spreadsheet Cell

Private Sub Worksheet_Change(ByVal Target As Range)     Dim cellContents As String     Dim valLength As Integer     cellContents = Trim(Str(Val(Target.Value)))     valLength = Len(cellContents)     If valLength <> 3 Then         MsgBox ("Please enter a 3 digit area code.")         Cells(9, "C").Select     Else         Cells(9, "C").Value = cellContents         Cells(9, "D").Select     End If End Sub