IF..Then Bedingung in Makro perfomanter machen
Guten Morgen miteinander!
Ich habe eine recht umfangreiche Tabelle mit Daten (ca. 9000 Datensätze), die automatisch über ein Makro befüllt wird (d.h.: die ANzahl der Datensätze ist variabel). Mein Problem besteht darin, dass in dieser Tabelle 25 Betragsfelder (Spalten) sind die nicht alle pro Datensatz gefüllt sind. Jetzt möchte ich die gefüllten Betragsfelder hinter die ID ziehen um die Tabelle übersichtlicher und vergleichbarere zu machen.
mit folgendem Makro bringe ich meinen Rechner aber fast zum ABsturz!
[Tabellenblattauswahl
Sheets("Prognose").Select
' Spalten einfügen
Columns("d:d").Select
Selection.Insert Shift:=xlToRight
' Spalten befüllen mit den Spaltennummern 1-8
' zählschleife
i = 4
Do Until IsEmpty(Cells(i, 3))
If Cells(i, 5) <> "" Then Cells(i, 4) = Cells(i, 5)
If Cells(i, 5) = "" Then Cells(i, 4) = Cells(i, 6)
If Cells(i, 5) = "" And Cells(i, 6) = "" Then Cells(i, 4) = Cells(i, 7)
If Cells(i, 5) = "" And Cells(i, 6) = "" And Cells(i, 7) = "" Then Cells(i, 4) = Cells(i, 8)
If Cells(i, 5) = "" And Cells(i, 6) = "" And Cells(i, 7) = "" And Cells(i, 8) = "" Then Cells(i, 4) = Cells(i, 9)
If Cells(i, 5) = "" And Cells(i, 6) = "" And Cells(i, 7) = "" And Cells(i, 8) = "" And Cells(i, 9) = "" Then Cells(i, 4) = Cells(i, 10)
If Cells(i, 5) = "" And Cells(i, 6) = "" And Cells(i, 7) = "" And Cells(i, 8) = "" And Cells(i, 9) = "" And Cells(i, 10) = "" Then Cells(i, 4) = Cells(i, 11)
If Cells(i, 5) = "" And Cells(i, 6) = "" And Cells(i, 7) = "" And Cells(i, 8) = "" And Cells(i, 9) = "" And Cells(i, 10) = "" And Cells(i, 11) = "" Then Cells(i, 4) = Cells(i, 12)
If Cells(i, 5) = "" And Cells(i, 6) = "" And Cells(i, 7) = "" And Cells(i, 8) = "" And Cells(i, 9) = "" And Cells(i, 10) = "" And Cells(i, 11) = "" And Cells(i, 12) = "" Then Cells(i, 4) = Cells(i, 13)
If Cells(i, 5) = "" And Cells(i, 6) = "" And Cells(i, 7) = "" And Cells(i, 8) = "" And Cells(i, 9) = "" And Cells(i, 10) = "" And Cells(i, 11) = "" And Cells(i, 12) = "" And Cells(i, 13) = "" Then Cells(i, 4) = Cells(i, 14)
If Cells(i, 5) = "" And Cells(i, 6) = "" And Cells(i, 7) = "" And Cells(i, 8) = "" And Cells(i, 9) = "" And Cells(i, 10) = "" And Cells(i, 11) = "" And Cells(i, 12) = "" And Cells(i, 13) = "" And Cells(i, 14) = "" Then Cells(i, 4) = Cells(i, 15)
If Cells(i, 5) = "" And Cells(i, 6) = "" And Cells(i, 7) = "" And Cells(i, 8) = "" And Cells(i, 9) = "" And Cells(i, 10) = "" And Cells(i, 11) = "" And Cells(i, 12) = "" And Cells(i, 13) = "" And Cells(i, 14) = "" And Cells(i, 15) = "" Then Cells(i, 4) = Cells(i, 16)
If Cells(i, 5) = "" And Cells(i, 6) = "" And Cells(i, 7) = "" And Cells(i, 8) = "" And Cells(i, 9) = "" And Cells(i, 10) = "" And Cells(i, 11) = "" And Cells(i, 12) = "" And Cells(i, 13) = "" And Cells(i, 14) = "" And Cells(i, 15) = "" And Cells(i, 16) = "" Then Cells(i, 4) = Cells(i, 17)
If Cells(i, 5) = "" And Cells(i, 6) = "" And Cells(i, 7) = "" And Cells(i, 8) = "" And Cells(i, 9) = "" And Cells(i, 10) = "" And Cells(i, 11) = "" And Cells(i, 12) = "" And Cells(i, 13) = "" And Cells(i, 14) = "" And Cells(i, 15) = "" And Cells(i, 16) = "" And Cells(i, 17) = "" Then Cells(i, 4) = Cells(i, 18) Else Cells(i, 4) = ""
i = i + 1
Loop
End Sub]
Gibt es eine Möglichkeit diese Bedingung perfomanter zu gestalten?
Herzlichen Dank schon mal für Eure Mühen!
Markus
Antwort schreiben
Antwort 7 von Markus76 vom 06.03.2019, 10:13 Options
Hallo!
Mit diesem COde klappt' jetzt:
i = 4
Do Until IsEmpty(Cells(i, 3))
If Cells(i, 5) <> "" And Cells(i, 6) <> "" And Cells(i, 7) <> "" And Cells(i, 8) <> "" And Cells(i, 9) <> "" And Cells(i, 10) <> "" And Cells(i, 11) <> "" And Cells(i, 12) <> "" And Cells(i, 13) <> "" And Cells(i, 14) <> "" And Cells(i, 15) <> "" And Cells(i, 16) <> "" And Cells(i, 17) <> "" And Cells(i, 18) <> "" And Cells(i, 19) <> "" And Cells(i, 20) <> "" And Cells(i, 21) <> "" And Cells(i, 22) <> "" And Cells(i, 23) <> "" And Cells(i, 24) <> "" And Cells(i, 24) <> "" And Cells(i, 25) <> "" And Cells(i, 26) <> "" Then
ElseIf Cells(i, 5) <> "" Then Cells(i, 4) = Cells(i, 5)
ElseIf Cells(i, 6) <> "" Then Cells(i, 4) = Cells(i, 6)
ElseIf Cells(i, 7) <> "" Then Cells(i, 4) = Cells(i, 7)
ElseIf Cells(i, 8) <> "" Then Cells(i, 4) = Cells(i, 8)
ElseIf Cells(i, 9) <> "" Then Cells(i, 4) = Cells(i, 9)
etc.
ElseIf Cells(i, 26) <> "" Then Cells(i, 4) = Cells(i, 26)
End If
i=i+1
end sub
Einziges Problemchen ist jetzt noch, dass die ersten zwei Zellen in denen das Ergebnis erscheinen sollte leerbleiben. Warum????
Trotzdem herzlichen Dank an alle, die bei der Lösung mitgewirkt haben!!
Markus