好的,请耐心等待我,我对Excel中的VBA很新。我一直试图弄清楚如何在我为错误检查制作的时间表中循环几天,我只是傻眼了。
我的时间表看起来像这样
所以我一直在尝试寻找一个循环来寻找空单元格。
我的范围是(" C4:I4")&我需要在从C4开始的29行上运行它。
GoTo 500
。MsgBox
以告知用户需要填写的内容。GoTo 500
来运行代码的保存文件部分。 非常感谢任何帮助。我已经浏览了论坛并试图让多个循环示例为我工作,但一直无法这样做。
Sub checkemptycells()
Dim x As String
Range("C1").Select
If ActiveCell.Text = "" Then
MsgBox "Pick Your Name"
GoTo 1000
End If
Range("G1").Select
If ActiveCell.Text = "" Then
MsgBox "ENTER A DATE"
GoTo 1000
End If
Range("C4").Select
If ActiveCell.Text = "" Then
MsgBox "Need Job#"
GoTo 1000
End If
Range("D4").Select
If ActiveCell.Text = "" Then
MsgBox "need qty."
GoTo 1000
End If
Range("E4").Select
If ActiveCell.Text = "" Then
MsgBox "Need Work Order!"
GoTo 1000
End If
Range("F4").Select
If ActiveCell.Text = "" Then
MsgBox "Pick a Dept.!"
GoTo 1000
End If
Range("G4:I4").Select
If ActiveCell.Text = "" Then
MsgBox "Fill Start & Stop times on this line"
GoTo 1000
End If
Dim FilePath As String
Dim FileName As String
Dim MyDate As String
Dim USER As String
FilePath = "Z:\TIMESHEETS\"
MyDate = Format(Now(), "mm_dd_yyyy_")
USER = (ActiveSheet.Range(" C1"))
FileName = FilePath & MyDate & USER
ActiveWorkbook.SaveAs FileName:=FileName, FileFormat:=xlWorkbookNormal
ActiveWorkbook.Close
OpenAfterPublish = False
xls.DisplayAlerts = False
1000
End Sub
答案 0 :(得分:0)
这样的事情会起作用吗?
Dim i as Variant
Dim j as Variant
For i = 4 to 32
For j = 3 to 9
If Cells(i,j).Value="" Then
MsgBox "Missing value in Cell(" & i & " ," & j & ")."
End If
Next j
Next i