Excel 查找列中的第一个空单元格并要求用户输入

Excel 查找列中的第一个空单元格并要求用户输入,excel,vba,Excel,Vba,我有一个很大的excel文件,B列上有不同的日期(它从第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 BallMillNu

我有一个很大的excel文件,B列上有不同的日期(它从第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

在循环中,只需添加步骤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

是的,这是可能的…@KazJaw你有一个例子吗?你需要向我们展示你尝试过的东西,然后我们帮助你把它做好。没有人会为你做这件事,除非他们心情非常好,或者无聊得发疯。在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'对于每一行,找到第一个空白单元格,并为currentRow=1选择它以rowCount currentRowValue=Cells(currentRow,sourceCol).Value如果为空(currentRowValue)或currentRowValue=“”,则单元格(currentRow,sourceCol)=输入框(“输入日期”)在我更改currentRow=7时结束(因为它从第7行开始)它不再起作用了。我只想找到从B7开始的第一个空单元格,然后输入日期。您可以再说明一些不起作用的内容吗。我用从B7开始的日期运行此操作(每隔一行跳过一次,并删除奇数行中的一些日期)它工作正常。我甚至删除了B7的日期,它仍然运行到完成。嘿..谢谢你的帮助!我用整个代码再次编辑了我的问题,以便你可以看到我在做什么。我必须,首先,阅读什么工作表(SheetBM)用户将输入一个日期。然后,使用此工作表..用户将在从B7开始的第一个空单元格中输入一个日期。我也不知道如何选择以前选择的工作表(我知道有一个“with”命令,但它总是给我一个错误消息)/它只是不运行。它读取代码的第一部分,但当它到达“空单元格查找器”部分时,当我使用currentRow=1运行时,它停止运行,没有错误。它运行(但要求输入两次日期)。但已填充的日期从第7行开始。当我更改currentRow=7时,它不会运行:(