Validation with a Spreadsheet Cell : Cell Value « Excel « VBA / Excel / Access / Word






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

 








Related examples in the same category

1.Define a string type variable and set to Cell(1,D)
2.StrConv("ALL LOWERCASE ", vbLowerCase)
3.Format("ALL LOWERCASE ", "<")
4.Checks values in a range 10 rows by 5 columns
5.Checks values in a range 10 rows by 5 columns with nested for loop
6.Place the value (result) of a formula into a cell rather than the formula.
7.Assing value in Cells to array, do the bubble sort and assign them back
8.transposes the values of a group of cells in a worksheet
9.Determining a cell's data type
10.Calculate cell