【发布时间】:2015-09-11 12:28:52
【问题描述】:
我在 B 列上有一个包含不同日期的大 excel 文件(它从第 7 行开始并跳转到第 9 行。例如,6 月 6 日 - B7,6 月 7 日 - B9,6 月 8 日 - B11)。 我想要一个宏来定位第一个空单元格(跳1行..例如单元格B7上有一个日期,所以宏应该验证单元格B9是否为空,而不是B8)然后要求用户输入此单元格上的日期。可能吗?
谢谢!
Sub BallMillInspection()
Dim BallMillNumber As String
' IDENTIFY WHAT BALL MILL
BallMillNumber = InputBox("Enter Ball Mill Number, e.g. 1")
If BallMillNumber = vbNullString Then Exit Sub
If BallMillNumber > 5 Then
MsgBox "This Ball Mill does not exist!"
End If
MsgBox "You are starting the inspection of Ball Mill " & BallMillNumber
Dim vSheet As Worksheet
Set vSheet = Sheets("BM " & BallMillNumber)
With vSheet
Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
Dim currentRowValue As String
sourceCol = 2 'column B has a value of 2
rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row 'for every row, find the first blank cell
For currentRow = 7 To rowCount Step 2
currentRowValue = Cells(currentRow, sourceCol).Value
If IsEmpty(currentRowValue) Or currentRowValue = "" Then
Cells(currentRow, sourceCol) = InputBox("Enter Date")
End If
Next
End With
End Sub
【问题讨论】:
-
是的,有可能……
-
@KazJaw 你有例子吗?
-
您需要向我们展示您尝试过的东西,然后我们会帮助您做对。除非他们心情非常好或无聊,否则没有人会为你做这件事。
-
检查this like '如何询问?和“如何搜索?”在 StackOverflow...
-
@KazJaw 我现在无法回答我自己的问题,所以.. 我会尝试使用评论。 Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer Dim currentRowValue As String sourceCol = 2 'B 列的值为 2 rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row '对于每一行,找到第一个空白单元格并选择它 For currentRow = 1 To rowCount currentRowValue = Cells(currentRow, sourceCol).Value If IsEmpty(currentRowValue) or currentRowValue = "" Then Cells(currentRow, sourceCol)=inputbox("Enter Date") End If下一个