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

Button

Button
15.02.2007 09:07:00
Chantal
Guten Morgen,diesen Code hat mir Ramses freundlicherweise geschrieben ich hätte Ihn jetzt gerne über einen Button bekomme es aber leider nicht hin.Könnte mir bitte jemand helfen?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim B As String
Dim i As Integer
Dim S As Long
Dim Summe As Long
Dim leftCol As Long, tarCol As Long
Select Case Target.Address(0, 0)
Case "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18"
With ActiveSheet
For i = 1 To Len(.Cells(Target.Row, 1))
B = Mid(.Cells(Target.Row, 1), i, 1)
For S = 1 To 50
If UCase(B) = UCase(.Cells(2, S)) Then
Summe = Summe + .Cells(3, S)
Exit For
End If
Next S
For S = 1 To 11
If UCase(B) = UCase(.Cells(5, S)) Then Summe = Summe + .Cells(6, S)
Next S
Next i
leftCol = .Cells(Target.Row, 254).End(xlToLeft).Column
'Definiere hier ab welcher Spalte geschrieben werden soll
If leftCol < 5 Then
tarCol = 2
Else
tarCol = leftCol - 3
End If
'... oder hier ab Spalte 2 das Ergebnis schreiben
If leftCol < 2 Then
'   tarCol = 2
Else
tarCol = leftCol + 1
End If
.Cells(Target.Row, tarCol) = Summe
End With
End Select
End Sub
GrussChantal

3
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Button
15.02.2007 10:22:45
fcs
Hallo Chantal,
die Prozedur müsste etwa so aussehen.
Gruß
Franz
Sub Test()
Dim Zelle As Range
Dim B As String
Dim i As Integer
Dim S As Long
Dim Summe As Long
Dim leftCol As Long, tarCol As Long
Set Zelle = ActiveCell
Select Case Zelle.Address(0, 0)
Case "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18"
With ActiveSheet
For i = 1 To Len(.Cells(Zelle.Row, 1))
B = Mid(.Cells(Zelle.Row, 1), i, 1)
For S = 1 To 50
If UCase(B) = UCase(.Cells(2, S)) Then
Summe = Summe + .Cells(3, S)
Exit For
End If
Next S
For S = 1 To 11
If UCase(B) = UCase(.Cells(5, S)) Then Summe = Summe + .Cells(6, S)
Next S
Next i
leftCol = .Cells(Zelle.Row, 254).End(xlToLeft).Column
'Definiere hier ab welcher Spalte geschrieben werden soll
If leftCol < 5 Then
tarCol = 2
Else
tarCol = leftCol - 3
End If
'... oder hier ab Spalte 2 das Ergebnis schreiben
If leftCol < 2 Then
'   tarCol = 2
Else
tarCol = leftCol + 1
End If
.Cells(Zelle.Row, tarCol) = Summe
End With
Case Else
MsgBox "Makro rechnet nur wenn eine der Zellen " & vbLf _
& "A10, A11, A12, A13, A14, A15, A16, A17 oder A18 gewählt ist"
End Select
End Sub

Anzeige
AW: Button
15.02.2007 11:02:28
Chantal
Hallo Franz,
Sorry die MsgBox sollte ganz raus und die Berechnung neben der Eingabe in Spalte B(B10;B11....)
ausgeführt werden.
Grüssle
Chantal
AW: Button
15.02.2007 16:56:38
fcs
Hallo Chantal,
dann könnte es etwa so aussehen. Nach Start des Makros werden nacheinander die Zellen im Bereich A10:A18 abgerbeitte und das Ergebnis jeweils in die Zelle rechts daneben eingetragen.
Gruß
Franz
Sub Test2()
Dim Zelle As Range
Dim B As String
Dim i As Integer
Dim S As Long
Dim Summe As Long
With ActiveSheet
For Each Zelle In .Range("A10:A18")
For i = 1 To Len(.Cells(Zelle.Row, 1))
B = Mid(.Cells(Zelle.Row, 1), i, 1)
For S = 1 To 50
If UCase(B) = UCase(.Cells(2, S)) Then
Summe = Summe + .Cells(3, S)
Exit For
End If
Next S
For S = 1 To 11
If UCase(B) = UCase(.Cells(5, S)) Then Summe = Summe + .Cells(6, S)
Next S
Next i
Zelle.Offset(0, 1) = Summe 'Summe in Spalte B eintragen
Next Zelle
End With
End Sub

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige