If abfrage über 2 sheets mit mehreren Variablen

Hallo und ein spezielles hallo an Reinhard,
Ich hab ein Problem an dem ich mir die Zähne ausbeise. Ich habe die Werte hart reingeschrieben, möchte aber die Werte variabel gestalten und aus einer anderen Tabelle holen und vergleichen. Die vielen Variablen und das Weiter den nächsten Vergleichswert holen sind die Probleme, wie bringe ich die unter einen Hut?
Grüße Wolfgang
_
Mein „theoretischer“ Aufbau:
y = 2
Do While Range(„A“ & y) „“
If Cells(y, 5).Value Like „AA“
‘ „AA“ = Range(“A1”)
And Cells(y, 6).Value = „16“
‘ „16“ = Range(“A2”)
And
if Cells(y, 27).Value Like „0“
Then nothing
if Cells(y, 27).Value Like „1“
Then Range(„N“ & y).Select
ActiveCell.FormulaR1C1 = „=RC[-1]-14“
if Cells(y, 27).Value Like „2“
Then Range(„L“ & y).Select
ActiveCell.FormulaR1C1 = „=RC[-1]-28“
if Cells(y, 27).Value Like „3“
Then Range(„M“ & y).Select
ActiveCell.FormulaR1C1 = „=RC[-1]-42“
Endif
Endif
Endif
Endif
ElseIf Cells(y, 5).Value Like „AA“ And Cells(y, 6).Value = „17“
‘ „AA“ = Range(“A1”)
‘ „17“ = Range(“A3”)weiter A1 mit A4 bis A1 A Ende__ AEnde = Wert X
And if Cells(y, 27).Value Like „0“
Then nothing
if Cells(y, 27).Value Like „1“
Then Range(„N“ & y).Select
ActiveCell.FormulaR1C1 = „=RC[-1]-14“
if Cells(y, 27).Value Like „2“
Then Range(„L“ & y).Select
ActiveCell.FormulaR1C1 = „=RC[-1]-28“
if Cells(y, 27).Value Like „3“
Then Range(„M“ & y).Select
ActiveCell.FormulaR1C1 = „=RC[-1]-42“
Endif
Endif
Endif
Endif
End If
y = y + 1
Loop

So sollte es sein:
y = 2
Do While sheets(“NL_14”). Range(„A“ & y) „“
If sheets(“NL_14”).Cells(y, 5).Value Like sheets(“14”).range(“A1”)
‘ A1 weiter B1 bis ?1 ?1 Wert = X
And sheets(“NL_14”).Cells(y, 6).Value = sheets(“14”).range(“A2”)
‘ A2 weiter A3 bis A? A? Wert = X
And
if sheets(“14”). Cells(y, 27).Value Like „0“
Then nix
if sheets(“14”). Cells(y, 27).Value Like „1“
Then sheets(“NL_14”).Range(„N“ & y).Select
ActiveCell.FormulaR1C1 = „=RC[-1]-14“
if sheets(“14”).Cells(y, 27).Value Like „2“
Then sheets(“NL_14”).Range(„L“ & y).Select
ActiveCell.FormulaR1C1 = „=RC[-1]-28“
if sheets(“14”). Cells(y, 27).Value Like „3“
Then sheets(“NL_14”).Range(„M“ & y).Select
ActiveCell.FormulaR1C1 = „=RC[-1]-42“
Endif
Endif
Endif
Endif
ElseIf ………………………………
End If
y = y + 1
Loop

Tabelle 14
__ A B C D ……………………………. AA AB AC AD……………….
1__AA BB CC DD X AA BB CC DD X
2__16 26 36 46 1 1 2 2
3__17 27 37 47 1 0 1 2
4__X 28 38 48 _ 1 3 1
5_____29 X 49 _ 3 _ 1
6_____X_____X

Tabelle NL_14
__ A B C D E F
1__123 B C D AA 16
2__222 B C D BB 66
3__565 B C D AA 17

Hallo Wolfang,

Hallo und ein spezielles hallo an Reinhard,

ich? Mein Name ist Hase und ich weiß grundsätzlich von nix :smile:

Du warst jetzt paarmal da, hast was gefragt und vielleicht hatte ich das Glück über eine Lösung für dich gestolpert zu sein.

So, jetzt kommt der Preis dafür den zu zahlen mußt wenn du schon wieder hier anfragst. :smile:

a) mach dich schlau, was ein pre-Tag bedeutet, er wird unterhalb des Eingabefensters erläutert oder tausendfach im Internet und benutze ihn unbedingt, egal Code, Einrückungen bei Tabellenauszügen.

Mich kostet es nur paar Klicks und ich habe den Code lesbar gemacht, also eingerückt, das hat hier nicht jeder und uneingerückt ist er nicht zu lesen, bzw. habe ich keine Lust zu.

b) auch wenn Niclaus wieder mit mir schimpft :smile: bitte immer die XLversion angeben.

c) was war das noch *grübel* ahja, bitte immer nur komplette Subs.

d)-h) das nächste Mal *grien*

Und, bevor du den Code hier bitte neu einstellst,
sowas

Then Range(„L“ & y).Select
ActiveCell.FormulaR1C1 = „=RC[-1]-28“

ändere das bitte überall gleich analog zu:
Then Range(„L“ & y).FormulaR1C1 = „=RC[-1]-28“

Select braucht kein Mensch, ist jetzt keinerlei Vorwurf *glaubmir*, ich weiß ja woher das kommt, vom Makrorekorder und der Vba-Hilfe.

**PS: An Alle, ich hab deshalb unten den Code so stehen lassen wie er ist, irgendwie fällt mir das (erst) seit 3-4 Wochen auf, woher kommen da diese mistigen Zeilen mitten im Code, vorne nur ein Doppelpunkt, danach nix? Die waren doch früher nicht da!?

Woher kommt der Mist, vom Team, von Wolfgang, von mir bzw. meinem Browser?**

Gruß
Reinhard

Mein „theoretischer“ Aufbau:

y = 2

Do While Range(„A“ & y) „“

If Cells(y, 5).Value Like „AA“

‘ „AA“ = Range(“A1”)

And Cells(y, 6).Value = „16“

‘ „16“ = Range(“A2”)

And

if Cells(y, 27).Value Like „0“

Then nothing

if Cells(y, 27).Value Like „1“

Then Range(„N“ & y).Select

ActiveCell.FormulaR1C1 = „=RC[-1]-14“

if Cells(y, 27).Value Like „2“

Then Range(„L“ & y).Select

ActiveCell.FormulaR1C1 = „=RC[-1]-28“

if Cells(y, 27).Value Like „3“

Then Range(„M“ & y).Select

ActiveCell.FormulaR1C1 = „=RC[-1]-42“

Endif

Endif

Endif

Endif

ElseIf Cells(y, 5).Value Like „AA“ And Cells(y, 6).Value =
„17“

‘ „AA“ = Range(“A1”)

‘ „17“ = Range(“A3”)weiter A1 mit A4 bis A1 A Ende__
AEnde = Wert X

And if Cells(y, 27).Value Like „0“

Then nothing

if Cells(y, 27).Value Like „1“

Then Range(„N“ & y).Select

ActiveCell.FormulaR1C1 = „=RC[-1]-14“

if Cells(y, 27).Value Like „2“

Then Range(„L“ & y).Select

ActiveCell.FormulaR1C1 = „=RC[-1]-28“

if Cells(y, 27).Value Like „3“

Then Range(„M“ & y).Select

ActiveCell.FormulaR1C1 = „=RC[-1]-42“

Endif

Endif

Endif

Endif

End If

y = y + 1

Loop

So sollte es sein:

y = 2

Do While sheets(“NL_14”). Range(„A“ & y) „“

If sheets(“NL_14”).Cells(y, 5).Value Like
sheets(“14”).range(“A1”)

‘ A1 weiter B1 bis ?1 ?1 Wert = X

And sheets(“NL_14”).Cells(y, 6).Value =
sheets(“14”).range(“A2”)

‘ A2 weiter A3 bis A? A? Wert = X

And

if sheets(“14”). Cells(y, 27).Value Like „0“

Then nix

if sheets(“14”). Cells(y, 27).Value Like „1“

Then sheets(“NL_14”).Range(„N“ & y).Select

ActiveCell.FormulaR1C1 = „=RC[-1]-14“

if sheets(“14”).Cells(y, 27).Value Like „2“

Then sheets(“NL_14”).Range(„L“ & y).Select

ActiveCell.FormulaR1C1 = „=RC[-1]-28“

if sheets(“14”). Cells(y, 27).Value Like „3“

Then sheets(“NL_14”).Range(„M“ & y).Select

ActiveCell.FormulaR1C1 = „=RC[-1]-42“

Endif

Endif

Endif

Endif

ElseIf ………………………………

End If

y = y + 1

Loop

Tabelle 14

__ A B C D ……………………………. AA AB AC AD……………….

1__AA BB CC DD X AA BB CC DD X

2__16 26 36 46 1 1 2 2

3__17 27 37 47 1 0 1 2

4__X 28 38 48 _ 1 3 1

5_____29 X 49 _ 3 _ 1

6_____X_____X

Tabelle NL_14

__ A B C D E F

1__123 B C D AA 16

2__222 B C D BB 66

3__565 B C D AA 17