String check function for az

I want:

  • loop for a specific column H(starting at H4) and
  • for each cell on this column, call the function to see if it is true (then do something) or if it turned out to be false (do something else).

I get a runtime error ***invalid use of property***on Call Isletter.

Sub IfBlank()

Dim Rng As Range
Dim MyCell As Range
Dim Isletter As Range

Set Rng = Range("H4:H" & Cells(Rows.Count, "H").End(xlUp).Row)

For Each MyCell In Rng
Call Isletter
If Isletter(MyCell.Value) = True Then
'do nothing
End If
If Isletter(MyCell.Value) = False Then
 MyCell.Value = "-"
 End If

 Next MyCell
End Sub

Public Function IsLetter(MyCell As String) As Boolean

    Dim intPos As Integer
    For intPos = 1 To Len(MyCell)
        Select Case Asc(Mid(MyCell, intPos, 1))
            Case 33 To 127
                Isletter = True
            Case Else
                Isletter = False
                Exit For
        End Select
    Next
End Function
+4
source share
3 answers

IsLettera function has an optional argument (MyCell As String), so you should always pass this argument and be a string.

If IsLetter(MyCell.Value) = True Then
  'do something
Else
  'do something else  
End If
+2
source

Code below

Thos line Range("H4:H" & Cells(Rows.Count, "H").End(xlUp).Row).Value2 = X .

Sub IfBlank()

Dim rng1 As Range
Dim X
Dim lngCnt As Long

Dim objRegex As Object
X = Range("H4:H" & Cells(Rows.Count, "H").End(xlUp).Row).Value2

Set objRegex = CreateObject("vbscript.regexp")

    With objRegex
         .IgnoreCase = True
         .Pattern = "[a-z]"

         For lngCnt = 1 To UBound(X)
            If .test(X(lngCnt, 1)) Then X(lngCnt, 1) = vbNullString
         Next
    End With

Range("H4:H" & Cells(Rows.Count, "H").End(xlUp).Row).Value2 = X

End Sub
+2

"" :

For Each MyCell In Rng
    If Isletter(MyCell.Value) = True Then
     'do nothing
    else
     MyCell.Value = "-"
    End If

Next MyCell

"IsLetter" . ASCII 127 "delete"

, ASCII 65-90 97 - 122 . ?

,

Public Function IsLetter(MyCell As String) As Boolean

Dim intPos As Integer
For intPos = 1 To Len(MyCell)
    Select Case Asc(Mid(Ucase(MyCell), intPos, 1))
        Case 90 To 122
            Isletter = True
            Exit Function
        Case Else
            Isletter = False
            Exit For
    End Select
Next
End Function
+1

Source: https://habr.com/ru/post/1628386/


All Articles