Anzeige
Archiv - Navigation
216to220
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
216to220
216to220
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

VBA: AND Funktion

VBA: AND Funktion
12.02.2003 13:16:27
Hans
hallo liebes forum,
bin ein ziemlicher anfänger desshalb bitte ich um nachsicht.
ich hab eine funktion in vba die aber nicht richtig ist.
im grunde soll sie dass gleiche machen wie eine
=wenn(and(x;x)=x;x;x) Funktion in Excel, Code sie sieht bissher so aus:

If ComboBox2 = "ändern" Then
Sheets("Baugruppe").Select
letzteZeile = ActiveSheet.UsedRange.Rows.Count
For j = 1 To letzteZeile
Cells.Find(What:=ComboBox1, After:=A1, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
if ActiveCell = ComboBox1 and_
ActiveCell.Offset(0, 1) = ComboBox1.List(ComboBox1.ListIndex, 1) and_
ActiveCell.Offset(0, 2) = TextBox1 and_
ActiveCell.Offset(0, 3) = TextBox2 and_
ActiveCell.Offset(0, 4) = TextBox3 and_
ActiveCell.Offset(0, 5) = TextBox4 and_
ActiveCell.Offset(0, 6) = TextBox5 and_
ActiveCell.Offset(0, 7) = TextBox6 and_
ActiveCell.Offset(0, 8) = TextBox7 and_
ActiveCell.Offset(0, 9) = TextBox8 and_
ActiveCell.Offset(0, 10) = TextBox9 and_
ActiveCell.Offset(0, 11) = TextBox10 and_
ActiveCell.Offset(0, 12) = TextBox11 and_
ActiveCell.Offset(0, 13) = TextBox12 and_
ActiveCell.Offset(0, 14) = TextBox13 and_
ActiveCell.Offset(0, 15) = TextBox14 and_
ActiveCell.Offset(0, 16) = TextBox15 and_
ActiveCell.Offset(0, 17) = TextBox16 and_
ActiveCell.Offset(0, 18) = TextBox17 and_
ActiveCell.Offset(0, 19) = TextBox18 and_
ActiveCell.Offset(0, 20) = TextBox19 and_
ActiveCell.Offset(0, 21) = TextBox20 and_
ActiveCell.Offset(0, 22) = TextBox21 and_
ActiveCell.Offset(0, 23) = TextBox22 and_
ActiveCell.Offset(0, 24) = TextBox23 and_
ActiveCell.Offset(0, 25) = TextBox24 and_
ActiveCell.Offset(0, 26) = TextBox25 and_
ActiveCell.Offset(0, 27) = TextBox26 and_
ActiveCell.Offset(0, 28) = TextBox27 and then Activecell.Select
Else
Next j


Dieser Code soll prüfen ob sich die markierte zelle an der richtigen stelle befindet, dass mit den "and" stimmt aber so nicht weiß jemand warum?

Gruß
Hans


6
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
Re: VBA: AND Funktion
12.02.2003 13:22:39
mkipke

Hallo Hans!

Die richtige Syntax der If-Bedingung lautet

If((Bedingung 1) and (Bedingung 2) ..... and (Bedingung n)) then
Anweisung 1
Anweisung 2
.
.
.
Anweisung n
else
Anweisung 1
Anweisung 2
.
.
.
Anweisung n
end if

Gruss, Manuel

Re: VBA: AND Funktion
12.02.2003 13:24:07
Steffen D

Hallo Hans,

probier das mal
Gruß
Steffen D

If ComboBox2 = "ändern" Then
Sheets("Baugruppe").Select
letzteZeile = ActiveSheet.UsedRange.Rows.Count
For j = 1 To letzteZeile
Cells.Find(What:=ComboBox1, After:=A1, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
If ActiveCell = ComboBox1 And _
ActiveCell.Offset(0, 1) = ComboBox1.List(ComboBox1.ListIndex, 1) And _
ActiveCell.Offset(0, 2) = TextBox1 And ActiveCell.Offset(0, 3) = TextBox2 And _
ActiveCell.Offset(0, 4) = TextBox3 And ActiveCell.Offset(0, 5) = TextBox4 And _
ActiveCell.Offset(0, 6) = TextBox5 And ActiveCell.Offset(0, 7) = TextBox6 And _
ActiveCell.Offset(0, 8) = TextBox7 And ActiveCell.Offset(0, 9) = TextBox8 And _
ActiveCell.Offset(0, 10) = TextBox9 And ActiveCell.Offset(0, 11) = TextBox10 And _
ActiveCell.Offset(0, 12) = TextBox11 And ActiveCell.Offset(0, 13) = TextBox12 And _
ActiveCell.Offset(0, 14) = TextBox13 And ActiveCell.Offset(0, 15) = TextBox14 And _
ActiveCell.Offset(0, 16) = TextBox15 And ActiveCell.Offset(0, 17) = TextBox16 And _
ActiveCell.Offset(0, 18) = TextBox17 And ActiveCell.Offset(0, 19) = TextBox18 And _
ActiveCell.Offset(0, 20) = TextBox19 And ActiveCell.Offset(0, 21) = TextBox20 And _
ActiveCell.Offset(0, 22) = TextBox21 And ActiveCell.Offset(0, 23) = TextBox22 And _
ActiveCell.Offset(0, 24) = TextBox23 And ActiveCell.Offset(0, 25) = TextBox24 And _
ActiveCell.Offset(0, 26) = TextBox25 And ActiveCell.Offset(0, 27) = TextBox26 And _
ActiveCell.Offset(0, 28) = TextBox27 Then ActiveCell.Select
Else
Next j

Anzeige
Re: VBA: AND Funktion
12.02.2003 13:40:20
Hans

hallo Steffen,
dass funktioniert schon mal super.
Kannst du mir vieleicht auch noch sagen warum er mir die meldung "next ohne for" rausgibt?

Gruß
Hans

Re: VBA: AND Funktion
12.02.2003 13:47:52
Steffen D

Hi,

das Else vor Next j gehört weg!
wofür brauchst du denn eine Schleife?
du benutzst ja die zählvariable gar nicht!?

Gruß
Steffen D

Re: VBA: AND Funktion
12.02.2003 13:53:56
Hans

Ohne else funktionierts auch nicht.
Mit der Schleife will ich den in einer Listbox markierten datensatz in der tabelle markieren damit ich den ändern kann.
Oder weißt du da was besseres?

Gruß
Hans

Re: VBA: AND Funktion
13.02.2003 08:33:07
Steffen D

Hi,

poste mal deinen ganzen Code!
wenn man nur einen kleinen Abschnitt hat, kann man nicht sagen was da nicht stimmt!

entweder hast du irgendwo ein End if vergessen, oder du hast ein next/bzw for zu viel!

Gruß
Steffen D

Anzeige

243 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige