Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
244to248
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
244to248
244to248
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Eintragen von Daten per Eingabemaske

Eintragen von Daten per Eingabemaske
17.04.2003 10:35:40
Chris
Hallo,

ich habe ein Prüfprotokoll erstellt, indem ich per Eingabemaske die Kopfdaten in die jeweiligen Blätter schreiben kann! In dem Blatt sind alle Blätter variabel (sind auswählbar), ausser das Blatt "Datenblatt"

Mein Problem jetzt ist, dass die Daten nicht in alle Blätter übertragen werden, sondern nur in das "Datenblatt"! Da alle Blätter aktiviert werden müssen habe ich auch ein Makro erstellt, welches alle Blätter aktiviert, selbst dann funktioniert es nicht!

Vielleicht hat jemand ne Idee, oder sieht meinen Fehler!

Mein Makro:

Private Sub cmdOK_Click()

Dim i As Integer
For i = 1 To Worksheets.Count

If Worksheets(i).Name = "Datenblatt" Then
'If Sheets("Datenblatt").Select Then
With Sheets("Datenblatt")
Cells(3, 3).Value = txtAuftragsnr.Value
Cells(4, 3).Value = txtAuftraggeber.Value
Cells(6, 3).Value = txtKunde.Value
Cells(7, 3).Value = txtProjektnr.Value
Cells(8, 3).Value = txtFiltertyp.Value
Cells(9, 3).Value = txtHersteller.Value
Cells(10, 3).Value = txtZeichnungsnr.Value
Cells(11, 3).Value = ComboBox4.Value + " " + ComboBox5.Value + " " + ComboBox6.Value
Cells(12, 3).Value = ComboBox7.Value + " " + ComboBox8.Value + " " + ComboBox9.Value

If ComboBox1 = "" And ComboBox2 = "" And ComboBox3 = "" Then
MsgBox ("Bitte Prüfdatum eingeben!!")
Else
Cells(5, 3).Value = ComboBox1.Value + " " + ComboBox2.Value + " " + ComboBox3.Value
End If

If ComboBox10 = "" And ComboBox11 = "" And ComboBox12 = "" Then
MsgBox ("Bitte Termin eingeben!!")
Else
Cells(7, 7).Value = ComboBox10.Value + " " + ComboBox11.Value + " " + ComboBox12.Value
End If

End If


If Worksheets(i).Name = "Reinheit ISO" Then
'If Sheets("Reinheit ISO") Then
With Sheets("Reinheit ISO")
Cells(12, 2).Value = txtAuftragsnr.Value
Cells(13, 2).Value = txtAuftraggeber.Value
Cells(14, 2).Value = ComboBox1.Value + " " + ComboBox2.Value + " " + ComboBox3.Value
Cells(15, 2).Value = txtKunde.Value
Cells(16, 2).Value = txtProjektnr.Value
Cells(17, 2).Value = txtFiltertyp.Value
Cells(18, 2).Value = txtHersteller.Value
Cells(19, 2).Value = txtZeichnungsnr.Value
Cells(20, 2).Value = ComboBox4.Value + " " + ComboBox5.Value + " " + ComboBox6.Value
Cells(21, 2).Value = ComboBox7.Value + " " + ComboBox8.Value + " " + ComboBox9.Value
'Cells(23, 2).Value = txtPrüfnorm.Value
End With
Else
End If
Exit For
'End If
End Sub

Danke im Voraus

Chris

9
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
Re: Eintragen von Daten per Eingabemaske
17.04.2003 10:49:20
ChrisL

Hallo Chris

Zwei Sachen sind mir aufgefallen...

Du beginnst mit For.., es fehlt aber ein "Next i" am Ende. Ferner beginnst du Block 1 mit With "Datenblatt", es fehlt aber ein End With.

Grundsätzlich musst du die Blätter nicht aktivieren. Das With... stellt den Bezug zum Blatt bereits her, es muss deshalb nicht aktiviert werden.

Bezogen auf Block 1 müsste es eigentlich wie folgt tun...

With Sheets("Datenblatt")
Cells(3, 3).Value = txtAuftragsnr.Value
Cells(4, 3).Value = txtAuftraggeber.Value
Cells(6, 3).Value = txtKunde.Value
Cells(7, 3).Value = txtProjektnr.Value
Cells(8, 3).Value = txtFiltertyp.Value
Cells(9, 3).Value = txtHersteller.Value
Cells(10, 3).Value = txtZeichnungsnr.Value
Cells(11, 3).Value = ComboBox4.Value + " " + ComboBox5.Value + " " + ComboBox6.Value
Cells(12, 3).Value = ComboBox7.Value + " " + ComboBox8.Value + " " + ComboBox9.Value

If ComboBox1 = "" And ComboBox2 = "" And ComboBox3 = "" Then
MsgBox ("Bitte Prüfdatum eingeben!!")
Else
Cells(5, 3).Value = ComboBox1.Value + " " + ComboBox2.Value + " " + ComboBox3.Value
End If

If ComboBox10 = "" And ComboBox11 = "" And ComboBox12 = "" Then
MsgBox ("Bitte Termin eingeben!!")
Else
Cells(7, 7).Value = ComboBox10.Value + " " + ComboBox11.Value + " " + ComboBox12.Value
End If

End With


Block 2:

With Sheets("Reinheit ISO")
Cells(12, 2).Value = txtAuftragsnr.Value
Cells(13, 2).Value = txtAuftraggeber.Value
Cells(14, 2).Value = ComboBox1.Value + " " + ComboBox2.Value + " " + ComboBox3.Value
Cells(15, 2).Value = txtKunde.Value
Cells(16, 2).Value = txtProjektnr.Value
Cells(17, 2).Value = txtFiltertyp.Value
Cells(18, 2).Value = txtHersteller.Value
Cells(19, 2).Value = txtZeichnungsnr.Value
Cells(20, 2).Value = ComboBox4.Value + " " + ComboBox5.Value + " " + ComboBox6.Value
Cells(21, 2).Value = ComboBox7.Value + " " + ComboBox8.Value + " " + ComboBox9.Value
'Cells(23, 2).Value = txtPrüfnorm.Value
End With


Gruss
Chris

Anzeige
Re: Eintragen von Daten per Eingabemaske
17.04.2003 10:50:41
Harald Kapp

Hallo Chris,
mindestens ein Bug ist m.E. drin:
Ab der folgenden Zeile:
With Sheets("Reinheit ISO")
Cells(12, 2).Value = txtAuftragsnr.Value

greift das makro trotzdem auf die Zellen des aktiven Arbeitsblattes, also wohl "Datenblatt" zu, da der Ausdruck Cells() implizit Activesheet.cells() bedeutet. Du hast schlicht einen Punkt vergessen:
With Sheets("Reinheit ISO")
.Cells(12, 2).Value = txtAuftragsnr.Value

Das müsste so funktionieren.

Ich würde übrigens anders vorgehen, um auf alle Arbeitsblätter eines Sheets zuzugreifen:

Gruß Harald




Anzeige
Re: Eintragen von Daten per Eingabemaske
17.04.2003 10:53:31
Harald Kapp

Hallo Chris,
die fehlenden Kontrollstrukturen sind mir gar nicht aufgefallen. Es wundert mich, dass VBA da nicht schon beim Übersetzen meckert.

Dennoch denke ich, dass auch in Deinem Code der Punkt fehlt:
With Sheets("Reinheit ISO")
.Cells(12, 2).Value = txtAuftragsnr.Value

Gruß Harald

Habe hier wiederrum ein Problem!
17.04.2003 10:59:53
Chris

Wenn ich jetzt nur eingebe:

With Sheets("Reinheit ISO")
Cells(12, 2).Value = txtAuftragsnr.Value
Cells(13, 2).Value = txtAuftraggeber.Value
Cells(14, 2).Value = ComboBox1.Value + " " + ComboBox2.Value + " " + ComboBox3.Value
Cells(15, 2).Value = txtKunde.Value
Cells(16, 2).Value = txtProjektnr.Value
Cells(17, 2).Value = txtFiltertyp.Value
Cells(18, 2).Value = txtHersteller.Value
Cells(19, 2).Value = txtZeichnungsnr.Value
Cells(20, 2).Value = ComboBox4.Value + " " + ComboBox5.Value + " " + ComboBox6.Value
Cells(21, 2).Value = ComboBox7.Value + " " + ComboBox8.Value + " " + ComboBox9.Value
'Cells(23, 2).Value = txtPrüfnorm.Value
End With


dann passiert folgendes Problem: Falls das Blatt "Reinheit ISO" nicht geöffnet ist, dann kommt "Fehler: ausserhalb des Bereichs"
Deshalb habe ich mit:

Dim i As Integer
For i = 1 To Worksheets.Count
If Worksheets(i).Name = "Datenblatt" Then
....
End if
For Next

gearbeitet! Habt Ihr mir da auch noch ne Lösung, bzw. die Einträge sind auf allen Blättern gleich! Gibt es da vielleicht noch ne Möglichkeit erst alle Blätter aufzulisten und dann die Werte einzutragen!?

Chris

Anzeige
Re: Habe hier wiederrum ein Problem!
17.04.2003 11:06:53
ChrisL

Hallo Chris

Muss Harald recht geben, der Bug liegt beim fehlenden Punkt.

Das Auswählen des Blattes ist dann nicht notwendig. Aber wenn du unbedingt willst :-) dann müsste es "Next i" am Ende heissen.

For i = 1 To Worksheets.Count
If Worksheets(i).Name = "Datenblatt" Then
....
End if
Next i

Gruss
Chris

KENNT SICH JEMAND AUS?
17.04.2003 13:07:40
Chris

Hallo,

ist hier vielleicht jemand, der mir helfen kann!

Chris

Schreihals!
17.04.2003 13:42:00
ChrisL

Anstatt blöde ins Forum zu schreien könntest du wie ein normaler Mensch eine Antwort geben. "Helfen können" müsste nun "helfen wollen" heissen.

Formular statt VBA Button.

Anzeige
Dann will mir jemand helfen!
17.04.2003 14:16:20
Chris

Mein Problem ist noch immer dasselbe:

Es funktioniert alles einwandfrei, wenn alle Blätter ausgewählt wurden! Wenn ein oder mehrere Blätter nicht enthalten sind, dann git er mit Laufzeitfehler "Ausserhalb des Bereichs an".

Ich suche jetzt eine Möglichkeit, welche dieses Problem ausschließt.

Mein Programm bis jetzt:

Dim Arbeitsblatt As Worksheet
For Each Arbeitsblatt In ActiveWorkbook.Sheets

With Sheets("Datenblatt")
.Cells(3, 3).Value = txtAuftragsnr.Value
.Cells(4, 3).Value = txtAuftraggeber.Value
.Cells(6, 3).Value = txtKunde.Value
.Cells(7, 3).Value = txtProjektnr.Value
.Cells(8, 3).Value = txtFiltertyp.Value
.Cells(9, 3).Value = txtHersteller.Value
.Cells(10, 3).Value = txtZeichnungsnr.Value
.Cells(11, 3).Value = ComboBox4.Value + " " + ComboBox5.Value + " " + ComboBox6.Value
.Cells(12, 3).Value = ComboBox7.Value + " " + ComboBox8.Value + " " + ComboBox9.Value
End With

....

Eine Möglichkeit, welche mein Problem ausschließt ist:

Dim i As Integer
For i = 1 To Worksheets.Count
If Worksheets(i).Name = "Name des Blattes" Then

Wie kann ich diesen Befehl in mein Programm mit einbauen!

Gruss Chris

PS: Wollte nicht rumschreien, bin nur etwas verzweifelt, da es nicht so funktioniert wie ich es möchte!

Anzeige
Re: Dann will mir jemand helfen!
17.04.2003 14:58:01
ChrisL

Hallo Chris

Also nochmals...

Private Sub cmdOK_Click()
With Sheets("Datenblatt")
.Cells(3, 3).Value = txtAuftragsnr.Value
.Cells(4, 3).Value = txtAuftraggeber.Value
.Cells(6, 3).Value = txtKunde.Value
.Cells(7, 3).Value = txtProjektnr.Value
.Cells(8, 3).Value = txtFiltertyp.Value
.Cells(9, 3).Value = txtHersteller.Value
.Cells(10, 3).Value = txtZeichnungsnr.Value
.Cells(11, 3).Value = ComboBox4.Value + " " + ComboBox5.Value + " " + ComboBox6.Value
.Cells(12, 3).Value = ComboBox7.Value + " " + ComboBox8.Value + " " + ComboBox9.Value
End With
End Sub

Dieser Teil funktioniert auch wenn das Blatt nicht ausgewählt ist. Wie du im ersten Beitrag geschrieben hast, ist das Blatt "Datenblatt" immer vorhanden.

Zu Teil 2. Entweder wie von Harald vorgeschlagen:
Dim Arbeitsblatt As Worksheet
For Each Arbeitsblatt In ActiveWorkbook.Sheets
MsgBox Arbeitsblatt.Name
Next

Oder mit einer For...Next Schlaufe. Hierzu kann ich mich auch nur zum x-ten mal wiederholen, dass ans Ende ein "Next i" gehört. Noch eine Wiederholung, das Blatt musst du dazu nicht auswählen (selektieren).

Private Sub cmdOK_Click()
Dim Arbeitsblatt As Worksheet

With Sheets("Datenblatt")
.Cells(3, 3).Value = txtAuftragsnr.Value
.Cells(4, 3).Value = txtAuftraggeber.Value
.Cells(6, 3).Value = txtKunde.Value
.Cells(7, 3).Value = txtProjektnr.Value
.Cells(8, 3).Value = txtFiltertyp.Value
.Cells(9, 3).Value = txtHersteller.Value
.Cells(10, 3).Value = txtZeichnungsnr.Value
.Cells(11, 3).Value = ComboBox4.Value + " " + ComboBox5.Value + " " + ComboBox6.Value
.Cells(12, 3).Value = ComboBox7.Value + " " + ComboBox8.Value + " " + ComboBox9.Value
End With


For Each Arbeitsblatt In ActiveWorkbook.Sheets

If Arbeitsblatt.Name = "Name des Blattes" Then
With Sheets("Name des Blattes")
.Cells(12, 2).Value = txtAuftragsnr.Value
.Cells(13, 2).Value = txtAuftraggeber.Value
.Cells(14, 2).Value = ComboBox1.Value + " " + ComboBox2.Value + " " + ComboBox3.Value
.Cells(15, 2).Value = txtKunde.Value
.Cells(16, 2).Value = txtProjektnr.Value
.Cells(17, 2).Value = txtFiltertyp.Value
.Cells(18, 2).Value = txtHersteller.Value
.Cells(19, 2).Value = txtZeichnungsnr.Value
.Cells(20, 2).Value = ComboBox4.Value + " " + ComboBox5.Value + " " + ComboBox6.Value
.Cells(21, 2).Value = ComboBox7.Value + " " + ComboBox8.Value + " " + ComboBox9.Value
End With
End If

Next Arbeitsblatt

End Sub

(Code getestet in Excel 97)

Gruss
Chris

Anzeige

299 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige