У меня проблемы с циклом в ячейках столбца. При использовании закомментированного оператора If вместо «Exit Do» под ним я запускаю бесконечный цикл. По какой-то причине мой код не перемещается по ячейкам даже с помощью 'cell.Offset (). Select'. При запуске кода он просто возвращает первый блок вместо того, чтобы проверять каждый блок до тех пор, пока не доберется до пустого блока и не покинет цикл «Do», чтобы снова запустить цикл «for».
'Macro is designed to Fill in blank spaces in column "F" depending on Passed, Non-Executed, or Failed Steps.
'Should fill in "F" if there exists an "F" in the filled in steps under it.
'Fills in "NE" if there is one present and no "F" present
'Fills in "P" if all else fails
Sub AutoFill()
Dim rng As Range, cell As Range
'Setting Variables, cell is used as current cell and rng is used as complete column of cells to check
Dim pf As String
'Variable that is assigned the cell values to check
'Set rng = Application.InputBox("Select a range", "Get Range", Type:=8)
Set rng = Range("F36:F66")
'Range setters, top one is input by the user once ran. It is input like follows '$Column$RowStart:$Column$RowEnd
For Each cell In rng
'Loops through set range and check each cell for the following
If IsEmpty(cell) = True And IsEmpty(Range("B" & cell.Row)) = True Then
'Checks if cell is empty and if the cell in the same row and column "B"
If IsEmpty(cell.Offset(1, 0)) = False Then
'Checks if cell under 'current cell' is empty
Dim TrackedCell As Range
Set TrackedCell = cell
'Creates variable that marks 'current empty cell'
pf = cell.Offset(1, 0).Value
'Assigns cell values of the cell under current cell to variable
cell.Offset(1, 0).Select
'Moves down 1 cell
'MsgBox "The value is" & TrackedCell.Value
Do
'Creates loop
'MsgBox "Loop starts"
If IsEmpty(TrackedCell) = True And pf = "F" Or (TrackedCell.Value = "P" And pf = "F") Or (TrackedCell.Value = "NE" And pf = "F") Then
'Checks if 'current empty cell' is still empty and if current cell value equals "F"
TrackedCell.Value = "F"
TrackedCell.Interior.ColorIndex = 6
'Sets 'current empty cell' to "F" and highlights cell
'MsgBox "If works"
ElseIf (IsEmpty(TrackedCell) = True And pf = "NE") Or (TrackedCell.Value = "P" And pf = "NE") Then
'Checks if 'current empty cell' is still empty and if current cell value equals "NE"
TrackedCell.Value = "NE"
TrackedCell.Interior.ColorIndex = 6
'Sets 'current empty cell' to "NE" and highlights cell
ElseIf IsEmpty(TrackedCell) = True And pf = "P" Then
'Checks if 'current empty cell' is still empty and if current cell value equals "P"
TrackedCell.Value = "P"
TrackedCell.Interior.ColorIndex = 6
'Sets 'current empty cell' to "P" and highlights cell
'Exit Do
'exits loop
End If
'MsgBox "What now"
pf = cell.Offset(1, 0).Value
cell.Offset(1, 0).Select
'Moves down 1 cell
'MsgBox "Should have moved down a cell"
'If IsEmpty(pf) = True Then
'MsgBox "Exit If Used"
'Exit Do
'End If
'exits loop
Exit Do
'MsgBox "Not Exit If"
Loop Until IsEmpty(pf) = True
'Loops through range checking and moving down cells until the next empty cell is found
End If
End If
Next cell
End Sub
MsgBoxes были для меня, чтобы проверить, были ли проблемы в программе во время работы.
Чтобы объяснить дальше. Я пытаюсь заполнить пустую ячейку в столбце, полном «F», «P» и «NE». Идея заключается в том, что если между этой пустой ячейкой в столбце и следующей пустой ячейкой в том же столбце присутствует буква «F», то в верхней пустой ячейке должна быть буква «F». Та же идея относится и к «NE», но «F» превзошла бы власть «NE». Если в полных ячейках под пустыми ячейками нет ни одного из них, ставится «P». В основном тесты были проведены и сгруппированы по категориям. Если один тест не пройден или не был выполнен в категории, все это помечается соответствующей меткой.
В приведенном ниже листе у меня есть пример того, как это будет выглядеть. Я пытаюсь сделать так, чтобы макрос автоматически заполнял пустое поле суб-теста или супер-теста в зависимости от процедур под ним.
Тестовый лист Excel