Allow alpha numeric values instead of isnumeric

89 Views Asked by At

I have the below code for entering a function and copying the orientation and borders of the above line. But in this it only accept numeric values, how can i modify the code so that i can enter alpa numeric values in that cell.

Below is the code

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("B:B")) Is Nothing Then
        If IsNumeric(Target.Value) Then ' Check if cell contains a numeric value
            If Target.Value <> "" Then
            Range("A" & Target.Row).Formula = "=IF(B" & Target.Row & "<>"""",ROW()-ROW($A$15)+1,"""")"
            ' Copy border, border color and orientation from row above
            With Range("A" & Target.Row & ":H" & Target.Row)
                .Borders.LineStyle = .Offset(-1, 0).Borders.LineStyle
                .Borders.Color = .Offset(-1, 0).Borders.Color
                .Orientation = .Offset(-1, 0).Orientation
            End With
        Else
            ' Check if entire row in column B is empty
            If WorksheetFunction.CountA(Range("B" & Target.Row & ":H" & Target.Row)) = 0 Then
                ' Delete entire row
                Rows(Target.Row).Delete
            Else
                ' Clear contents of column A to H for the row where value was deleted in column B
                Range("A" & Target.Row & ":H" & Target.Row).ClearContents
            End If
        End If
    End If
End If
End Sub
1

There are 1 best solutions below

1
CLR On

Here's a small Function you could add to your code, to give it IsAlphaNumeric functionality.

Function IsAlphaNumeric(t) as Boolean
    Dim i as Long
    IsAlphaNumeric = True
    For i = 1 To Len(t)
        If Not (Mid(t, i, 1) Like "[A-z0-9]") Then
            IsAlphaNumeric = False
            Exit For
        End If
    Next
End Function

You can use it like this:

If IsAlphaNumeric(Target.Value) Then ' Check if cell contains alpha-numeric value