Reputation: 161
The code below is suppose to verify if the range of column 23 has only numeric values. When pressing the command button, I get the error Invalid Qualifier on the row If Not IsNumeric(sh1.Cells(k, 23)).Value Then
. Any help to fix the problem will be must appreciated. Please find the code attached below.
Note: the code needs to be under a command button.
Private Sub CommandButton1_Click()
Dim k As Long
Dim sh1 As Worksheet, wb1 As Workbook
Set wb1 = Excel.ActiveWorkbook
Set sh1 = wb1.Worksheets(1)
Application.EnableEvents = False
For k = 5 To 1000
If Not IsNumeric(sh1.Cells(k, 23)).Value Then
sh1.Cells(k, 23).Interior.Color = RGB(255, 0, 0)
ElseIf sh1.Cells(k, 23).Value = "" Then
sh1.Cells(k, 23).Interior.Color = RGB(255, 255, 255)
Else
sh1.Cells(k, 23).Value = WorksheetFunction.Round(sh1.Cells(k, 23).Value, 0)
sh1.Cells(k, 23).Interior.Color = RGB(255, 255, 255)
End If
Next k
Application.EnableEvents = True
End Sub
Upvotes: 0
Views: 306
Reputation: 34055
You've got the bracket in the wrong place - it should be:
If Not IsNumeric(sh1.Cells(k, 23).Value) Then
Upvotes: 1