I wrote this sub:
But I have problem on this line:
Range("F6").Formula = "=SUM(COUNTIF(A1:A & LastRowIndex,"
Where A1 :A & LastRowIndex is not true. If I hardcode A1:A10 then it works. But I want to put LastRowIndex so that program can find the end value.
Any help is appreciated.
Thanks
Code:
Sub TextToNumbe()
Dim rCell As Range
Dim sMyString As String
Dim LastRowIndex As Long
LastRowIndex = Cells(Rows.Count, "A").End(xlUp).Row
On Error GoTo ErrorHandle
With Sheets("Sheet1").Range("A1:A10")
.NumberFormat = "General"
.Value = .Value
End With
Sheets("Sheet1").Select
'Range("F6").Formula = "=SUM(COUNTIF(A1:A10," _
'& "{""A"",""B"",""C"",""D"",""E"",""F"",""G"",""H"",""I"",""J"",""K"",""L""," _
'& """M"",""N"",""O"",""P"",""Q"",""R"",""S"",""T"",""U"",""V"",""W"",""X"",""Y"",""Z""," _
'& """!"",""@"",""#"",""$"",""%"",""^"",""&"",""*"",""/"","">"",""<"","","",""~"","";"","":""," _
'& """?"",""-"",""+"",""("","")""}))"
Range("F6").Formula = "=SUM(COUNTIF(A1:A & LastRowIndex," _
& "{""A"",""B"",""C"",""D"",""E"",""F"",""G"",""H"",""I"",""J"",""K"",""L""," _
& """M"",""N"",""O"",""P"",""Q"",""R"",""S"",""T"",""U"",""V"",""W"",""X"",""Y"",""Z""," _
& """!"",""@"",""#"",""$"",""%"",""^"",""&"",""*"",""/"","">"",""<"","","",""~"","";"","":""," _
& """?"",""-"",""+"",""("","")""}))"
Set rCell = Range("A1:A" & LastRowIndex)
If Range("F6").Value > 0 Then
MsgBox "Contains special character in range [ " & rCell.Address & " ]. Please check and try again.", vbInformation, "Data Validation"
End If
Done:
Exit Sub
ErrorHandle:
MsgBox Err.Description & " Error in procedure CellCheck."
End Sub
But I have problem on this line:
Range("F6").Formula = "=SUM(COUNTIF(A1:A & LastRowIndex,"
Where A1 :A & LastRowIndex is not true. If I hardcode A1:A10 then it works. But I want to put LastRowIndex so that program can find the end value.
Any help is appreciated.
Thanks