Este é o código no qual estou tendo um erro no Excel:
Sub Start_EndDelayInMonth()
With Sheets("Analysis Worksheet")
Dim i As Long
Dim LastRow As Long
LastRow = Range("N" & Rows.Count).End(xlUp).Row
'This is where the error occurs.
If Sheets("Analysis Worksheet").Cells(i, 2).Value = 1 And Sheets("Analysis Worksheet").Cells(i, 3).Value = 1 Then
Call CopyCells
End If
If Sheets("Analysis Worksheet").Range("B" & i).Value = 1 And Sheets("Analysis Worksheet").Range("C" & i).Value = 2 Then
Call CopyCells
End If
If Sheets("Analysis Worksheet").Range("B" & i).Value = 1 And Sheets("Analysis Worksheet").Range("C" & i).Value = 3 Then
Call CopyCells
End If
'--Then the code continues on in the same fashion, ending with:
End With
End Sub
Alguém por favor pode me ajudar a entender por que estou recebendo o erro de tempo de execução? Obrigada!
O código do CopyCells é:
Sub CopyCells()
Dim i As Long
Dim j As Long
Dim k As Long
Dim LastRow As Long
LastRow = Range("N" & Rows.Count).End(xlUp).Row
j = 26
k = 2
For i = 5 To LastRow
Sheets("Analysis Worksheet").Cells(i, j).Value = Sheets("Analysis Worksheet").Cells(i, (j - k)).Value
Sheets("Analysis Worksheet").Cells(i, (j - k)).Value = Sheets("Analysis Worksheet").Cells(i, (j - (k + 1))).Value
Sheets("Analysis Worksheet").Cells(i, (j - (k + 1))).Value = Sheets("Analysis Worksheet").Cells(i, (j - (k + 2))).Value
Sheets("Analysis Worksheet").Cells(i, (j - (k + 2))).Value = Sheets("Analysis Worksheet").Cells(i, (j - (k + 3))).Value
Sheets("Analysis Worksheet").Cells(i, (j - (k + 3))).Value = Sheets("Analysis Worksheet").Cells(i, (j - (k + 4))).Value
Sheets("Analysis Worksheet").Cells(i, (j - (k + 4))).Value = Sheets("Analysis Worksheet").Cells(i, (j - (k + 5))).Value
Sheets("Analysis Worksheet").Cells(i, (j - (k + 5))).Value = Sheets("Analysis Worksheet").Cells(i, (j - (k + 6))).Value
Sheets("Analysis Worksheet").Cells(i, (j - (k + 6))).Value = Sheets("Analysis Worksheet").Cells(i, (j - (k + 7))).Value
Sheets("Analysis Worksheet").Cells(i, (j - (k + 7))).Value = Sheets("Analysis Worksheet").Cells(i, (j - (k + 8))).Value
Sheets("Analysis Worksheet").Cells(i, (j - (k + 8))).Value = Sheets("Analysis Worksheet").Cells(i, (j - (k + 9))).Value
Sheets("Analysis Worksheet").Cells(i, (j - (k + 9))).Value = Sheets("Analysis Worksheet").Cells(i, (j - (k + 10))).Value
Sheets("Analysis Worksheet").Cells(i, (j - (k + 10))).Value = Sheets("Analysis Worksheet").Cells(i, (j - (k + 11))).Value
Sheets("Analysis Worksheet").Cells(i, (j - (k + 11))).Value = 0
j = j + 1
k = k + 1
Next i
If k < (k + 1) Then
Sheets("Analysis Worksheet").Cells(i, (j - (k + 10))).Value = 0
End If
End Sub