Voici le code sur lequel je rencontre une erreur dans 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
Quelqu'un peut-il m'aider s'il vous plaît à comprendre pourquoi je reçois l'erreur d'exécution? Je vous remercie!
Le code CopyCells est:
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
microsoft-excel-2010
vba
Bruyère
la source
la source
If Sheets("Analysis Worksheet").Cells(i, 2).Value = 1 And Sheets("Analysis Worksheet").Cells(i, 3).Value = 1 Then
<<< - c'est là que j'ai l'erreur @benjaminS, j'ai défini " "plus tôt dans mon code, en haut. J'ai fini par réparer mon erreur. Merci pour les commentaires cependant! :)Réponses:
Votre code est
Vous pouvez voir que pendant que vous avez défini
i
- aucune valeur n’est assignée.la source