Anzeige
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Fehler im VBA Code

Forumthread: Fehler im VBA Code

Fehler im VBA Code
26.02.2006 15:01:42
Josef
Hallo!
Im aktiven Arbeitsblatt sind in der SpalteA von A2-A10 Namen.
In der SpalteB von B2-B10 ist der 01.01.2006 eingetragen.
Im aktiven Arbeitsblatt sind in der SpalteC von C2-C10 Werte eingetragen.
Beispiel:
A2= Maier,B2= 01.01.2006, C2= 100
A3= Huber,B3= 01.01.2006, C3= 200
Wenn ich jetzt den CommandButton2 drücke, so wird wenn der Name Maier zutrifft,der Wert 100 in der Userform in die Textbox2 eingetragen.
Wenn jedoch der Name Huber zutrifft, so wird nicht 200 so wie vorgesehen, sondern 100 in die TextBox18 eingetragen.
Wo habe ich bitte hier den Fehler?
Danke
Josef
Private Sub CommandButton2_Click()
If Nametxt1 = usertxt1 And _
Label72.Caption = "Hauskrankenpflege über 4 Wochen" And _
Label78.Caption = "Heilbehelfe und Hilfsmittel" And _
Label84.Caption = "KH - Aufnahmeanzeigen" Then
Dim rngFind As Range
Dim intCount As Integer, intCol As Integer, lngRow As Long
If Not IsDate(datumtxt1) Then Exit Sub
With ActiveSheet
Set rngFind = .Range("B:B").Find(What:=CDate(datumtxt1), LookAt:=xlWhole, LookIn:=xlFormulas)
If Not rngFind Is Nothing Then
lngRow = rngFind.Row
intCol = 3
For intCount = 2 To 16
Select Case intCount
Case 2 To 16
Controls("TextBox" & intCount) = ""
Controls("TextBox" & intCount) = .Cells(lngRow, intCol)
intCol = intCol + 1
Case Else
lngRow = lngRow + 1
intCol = 3
End Select
Next
End If
Set rngFind = Nothing
End With
Else
If Nametxt2 = usertxt1 And _
Label72.Caption = "Hauskrankenpflege über 4 Wochen" And _
Label78.Caption = "Heilbehelfe und Hilfsmittel" And _
Label84.Caption = "KH - Aufnahmeanzeigen" Then
Dim rngFind1 As Range
Dim intCount1 As Integer, intCol1 As Integer, lngRow1 As Long
If Not IsDate(datumtxt1) Then Exit Sub
With ActiveSheet
Set rngFind1 = .Range("B:B").Find(What:=CDate(datumtxt1), LookAt:=xlWhole, LookIn:=xlFormulas)
If Not rngFind1 Is Nothing Then
lngRow1 = rngFind1.Row
intCol1 = 3
For intCount1 = 18 To 32
Select Case intCount1
Case 18 To 32
Controls("TextBox" & intCount1) = ""
Controls("TextBox" & intCount1) = .Cells(lngRow1, intCol1)
intCol1 = intCol1 + 1
Case Else
lngRow1 = lngRow1 + 1
intCol1 = 3
End Select
Next
End If
Set rngFind1 = Nothing
End With
Anzeige

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Fehler im VBA Code
26.02.2006 15:33:53
Reinhard
Hi Josef,
poste mal die komplette Sub, hier fehlt zumindest ein end if und ein end sub, dann wird es auch lesbar da die Einrückungen erhalten bleiben.
Gruß
Reinhard
ps: Ich freue mich über eine Rückmeldung ob diese Antwort hilfreich war oder nicht..
AW: Fehler im VBA Code
26.02.2006 15:36:30
Josef
Hallo Reinhard!
hier der komplette Code con CB2

Private Sub CommandButton2_Click()
If Nametxt1.Text = usertxt1 And _
Label72.Caption = "Hauskrankenpflege über 4 Wochen" And _
Label78.Caption = "Heilbehelfe und Hilfsmittel" And _
Label84.Caption = "KH - Aufnahmeanzeigen" Then
Dim rngFind As Range
Dim intCount As Integer, intCol As Integer, lngRow As Long
If Not IsDate(datumtxt1) Then Exit Sub
With ActiveSheet
Set rngFind = .Range("B:B").Find(What:=CDate(datumtxt1), LookAt:=xlWhole, LookIn:=xlFormulas)
If Not rngFind Is Nothing Then
lngRow = rngFind.Row
intCol = 3
For intCount = 2 To 16
Select Case intCount
Case 2 To 16
Controls("TextBox" & intCount) = ""
Controls("TextBox" & intCount) = .Cells(lngRow, intCol)
intCol = intCol + 1
Case Else
lngRow = lngRow + 1
intCol = 3
End Select
Next
End If
Set rngFind = Nothing
End With
Else
If Nametxt2.Text = usertxt1 And _
Label72.Caption = "Hauskrankenpflege über 4 Wochen" And _
Label78.Caption = "Heilbehelfe und Hilfsmittel" And _
Label84.Caption = "KH - Aufnahmeanzeigen" Then
Dim rngFind1 As Range
Dim intCount1 As Integer, intCol1 As Integer, lngRow1 As Long
If Not IsDate(datumtxt2) Then Exit Sub
With ActiveSheet
Set rngFind1 = .Range("B:B").Find(What:=CDate(datumtxt2), LookAt:=xlWhole, LookIn:=xlFormulas)
If Not rngFind1 Is Nothing Then
lngRow1 = rngFind1.Row
intCol1 = 3
For intCount1 = 18 To 32
Select Case intCount1
Case 18 To 32
Controls("TextBoxA" & intCount1) = ""
Controls("TextBoxA" & intCount1) = .Cells(lngRow1, intCol1)
intCol1 = intCol1 + 1
Case Else
lngRow1 = lngRow1 + 1
intCol1 = 3
End Select
Next
End If
Set rngFind1 = Nothing
End With
Else
If Nametxt3.Text = usertxt1 And _
Label72.Caption = "Hauskrankenpflege über 4 Wochen" And _
Label78.Caption = "Heilbehelfe und Hilfsmittel" And _
Label84.Caption = "KH - Aufnahmeanzeigen" Then
Dim rngFind2 As Range
Dim intCount2 As Integer, intCol2 As Integer, lngRow2 As Long
If Not IsDate(datumtxt1) Then Exit Sub
With ActiveSheet
Set rngFind2 = .Range("B:B").Find(What:=CDate(datumtxt1), LookAt:=xlWhole, LookIn:=xlFormulas)
If Not rngFind2 Is Nothing Then
lngRow2 = rngFind2.Row
intCol2 = 3
For intCount2 = 34 To 48
Select Case intCount2
Case 34 To 48
Controls("TextBox" & intCount2) = ""
Controls("TextBox" & intCount2) = .Cells(lngRow2, intCol2)
intCol2 = intCol2 + 1
Case Else
lngRow2 = lngRow2 + 1
intCol2 = 3
End Select
Next
End If
Set rngFind2 = Nothing
End With
End If
End If
End If
End Sub

Josef
Anzeige
;

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige