I am new to vba and i am trying to write a code to validate the "A" column. if the cell character length = 16 then add the letter "C" to the cell.
if the cell not <> 9 and it is <> 16 then delete the info entered in the cell. I would like the cell that was deleted to still be selected after the validation of the cell is done (this part is optional though). The primary thing is to validate the cell. I got both codes to work but not at the same time. if it captures one condition it misses out the other.
Kindly assist thank you.
below is a sample of the code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Worksheets("Sheet1").Range("a8:a") <> "" Then
If Len(Target.Value) = 16 Then
Target.Value = "C" & Target.Value
MsgBox ("test")
End If
End If
If Worksheets("Sheet1").Range("a8:a") <> "" Then
If Len(Target.Value) <> 9 And Len(Target.Value) <> 16 Then
MsgBox ("test again")
Target.Value = Left(Target.Value, 0)
End If
End If
End Sub
Bookmarks