无法跟踪某个单元格并使这些单元格的范围等于新变量

时间:2019-05-22 19:19:26

标签: excel vba

我正在尝试选择一个单元格以通过循环检查单元格中的条件来跟踪循环在单元格中向下移动的时间。如果满足条件,我希望根据满足的条件填写所选单元格。我不断在行Set TrackedCell = Range(cell)上遇到运行时错误'1004',“对象'_Global'的方法'范围'失败”。您如何跟踪或记录循环中的上一个单元格?

Sub AutoFill()
Dim rng As Range, cell As Range
'Set rng = Application.InputBox("Select a range", "Get Range", Type:=8)
Set rng = Range("F36:F66")
For Each cell In rng
    If IsEmpty(cell) = True And IsEmpty(Range("B" & cell.Row)) = True Then
        If IsEmpty(cell.Offset(-1, 0)) = True Then
            Dim TrackedCell As Range
            Set TrackedCell = Range(cell)
            TrackedCell.Offset(0, 1).Select
            cell.Offset(1, 0).Select
            Do Until IsEmpty(cell) = True
                If IsEmpty(TrackedCell) = False And InStr(1, celltxt, "F") Then
                    TrackedCell.Value = "F"
                ElseIf IsEmpty(TrackedCell) = False And InStr(1, celltxt, "NE") Then
                    TrackedCell.Value = "NE"
                ElseIf IsEmpty(TrackedCell) = False And InStr(1, celltxt, "P") Then
                    TrackedCell.Value = "P"
                End If
            Loop
            'Dim Subtest As Range
        End If
    End If
Next cell
End Sub

0 个答案:

没有答案