0

我在 B 列上有一个带有不同日期的大 excel 文件(它从第 7 行开始并跳转到第 9 行 .. 例如 June6th - B7、 June 7th - B9、 June 8th - 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
4

1 回答 1

0

在您的循环中,只需添加第 2 步即可移动两个单元格

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 and select it
'added Step 2
For currentRow = 1 To rowCount Step 2
    currentRowValue = Cells(currentRow, sourceCol).Value
    If IsEmpty(currentRowValue) Or currentRowValue = "" Then
        Cells(currentRow, sourceCol) = InputBox("Enter Date")
    End If
Next
于 2013-06-12T18:42:20.667 回答