|
pandengyisun 发表于 2015-11-26 11:47
很感谢你。但如果不加On Error Resume Next这个语句,如果Excel里面什么都不填,会出错。如下图:
嗯,见下- Sub check()
- Dim rg As Range, r%, c%, xh%, str$
- Set rg = Sheets(1).UsedRange.Find("件号/规格型号")
- r = rg.Row
- c = rg.Column
- For xh = r + 1 To 300
- If IsEmpty(Cells(xh, c)) Then
- If Application.WorksheetFunction.CountA(Range(Cells(xh, 1), Cells(xh, c - 1))) > 0 Then
- str = str & "," & xh
- End If
- Else
- If Application.WorksheetFunction.CountA(Range(Cells(xh, 1), Cells(xh, c - 1))) <> 1 Then
- str = str & "," & xh
- End If
- End If
- Next xh
- If Len(str) = 0 Then
- MsgBox "检查完毕,无错误"
- Else
- MsgBox "第" & Right(str, Len(str) - 1) & "行存在错误"
- End If
- End Sub
复制代码 |
|