以下代码用于验证第23列的范围是否仅包含数值。按下命令按钮时,我在行If Not IsNumeric(sh1.Cells(k, 23)).Value Then
上收到错误无效限定符。任何帮助解决问题将是必须的。请找到下面的代码。
注意:代码需要在命令按钮下。
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
答案 0 :(得分:1)
你的支架位置错误 - 应该是:
If Not IsNumeric(sh1.Cells(k, 23).Value) Then