Supportnet / Forum / Tabellenkalkulation
Excel - ...Makro?
Frage
Hallo,
und zwar würde ich gerne folgendes in Excel hinbekommen:
Wenn ich eine bestimmte Zelle anklicke, sollen bestimmte Zellen eine andere Formatierung annehmen, also hervorgehoben werden. Klicke ich als nächstes auf eine andere bestimmte Zelle, so sollen wieder bestimmte Zellen anders formatiert werden, aber die da vor eine neue Formatierung angenommen haben, sollen wieder ihre alte bekommen.
Ich hoffe es versteht einer und kann mir helfen ;)
Danke schon mal
Antwort 1 von nighty
hi micha :)
kleines beispiel,reagiert auf doppelclick
einzufuegen vbeditor/projektexplorer/tabelle1
zur zeit ist zelle 1,1 und 5,5 bei doppelclick rot bzw. gelb ansonsten schwarz.
gruss micha
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Application.EnableEvents = False
Set LastCell = ActiveSheet.Cells.SpecialCells(xlLastCell)
alta = LastCell.Row
a = LastCell.Row
Do While Application.CountA(Rows(a)) = 0 And a <> 1
a = a - 1
Loop
alta = a
altb = LastCell.Column
b = LastCell.Column
Do While Application.CountA(Columns(b)) = 0 And b <> 1
b = b - 1
Loop
altb = b
lzeile = alta
lspalte = altb
lzeile1 = Selection.Row
lspalte1 = Selection.Column
With Worksheet
For t0 = 1 To lspalte
For t1 = 1 To lzeile
Cells(t1, t0).Font.ColorIndex = 0
rem hier deine erste zelle mit 1 fuer zeile und 1 fuer spalte
If lzeile1 = 1 And lspalte1 = 1 Then
Cells(t1, t0).Font.ColorIndex = 3
End If
rem hier deine erste zelle mit 5 fuer zeile und 5 fuer spalte
If lzeile1 = 5 And lspalte1 = 5 Then
Cells(t1, t0).Font.ColorIndex = 6
End If
Next t1
Next t0
End With
Application.EnableEvents = True
End Sub
kleines beispiel,reagiert auf doppelclick
einzufuegen vbeditor/projektexplorer/tabelle1
zur zeit ist zelle 1,1 und 5,5 bei doppelclick rot bzw. gelb ansonsten schwarz.
gruss micha
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Application.EnableEvents = False
Set LastCell = ActiveSheet.Cells.SpecialCells(xlLastCell)
alta = LastCell.Row
a = LastCell.Row
Do While Application.CountA(Rows(a)) = 0 And a <> 1
a = a - 1
Loop
alta = a
altb = LastCell.Column
b = LastCell.Column
Do While Application.CountA(Columns(b)) = 0 And b <> 1
b = b - 1
Loop
altb = b
lzeile = alta
lspalte = altb
lzeile1 = Selection.Row
lspalte1 = Selection.Column
With Worksheet
For t0 = 1 To lspalte
For t1 = 1 To lzeile
Cells(t1, t0).Font.ColorIndex = 0
rem hier deine erste zelle mit 1 fuer zeile und 1 fuer spalte
If lzeile1 = 1 And lspalte1 = 1 Then
Cells(t1, t0).Font.ColorIndex = 3
End If
rem hier deine erste zelle mit 5 fuer zeile und 5 fuer spalte
If lzeile1 = 5 And lspalte1 = 5 Then
Cells(t1, t0).Font.ColorIndex = 6
End If
Next t1
Next t0
End With
Application.EnableEvents = True
End Sub
Antwort 2 von nighty
hi micha :)
alternativ gibt es groesser kleiner gleich als deine lieblingszelle :)
sag mal welche und was passieren soll :)
gruss nighty
alternativ gibt es groesser kleiner gleich als deine lieblingszelle :)
sag mal welche und was passieren soll :)
gruss nighty
Antwort 3 von Micha123
Danke für die schnelle Antwort.
Ich glaub, ich hab mich ein bissel dumm ausgedrückt.. und zwar..
Bei deiner Beispiel Config wird, wenn ich Zelle A1 anklicke, jede Zelle rot. Ich will aber das zum Beispiel, wenn ich Zelle A1 anklicke, B4 und C2 nur rot werden. Würde das ganze auch mit nur einem Klick funktionieren, also nicht Doppelklick?
Wie man merkt kenn ich mich damit überhaupt nicht aus.
Ich glaub, ich hab mich ein bissel dumm ausgedrückt.. und zwar..
Bei deiner Beispiel Config wird, wenn ich Zelle A1 anklicke, jede Zelle rot. Ich will aber das zum Beispiel, wenn ich Zelle A1 anklicke, B4 und C2 nur rot werden. Würde das ganze auch mit nur einem Klick funktionieren, also nicht Doppelklick?
Wie man merkt kenn ich mich damit überhaupt nicht aus.
Antwort 4 von nighty
hi micha :)
vbeditor/projektexplorer/tabelle1 alternativ die mappe einzufuegen
reagiert auf zellenwechsel
a1 click > B4+C2 rot ansonsten schwarz
gruss nighty
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
With Worksheet
If Selection.Row = 1 And Selection.Column = 1 Then
Cells(4, 2).Font.ColorIndex = 3
Cells(2, 3).Font.ColorIndex = 3
Else
Cells(4, 2).Font.ColorIndex = 0
Cells(2, 3).Font.ColorIndex = 0
End If
End With
Application.EnableEvents = True
End Sub
vbeditor/projektexplorer/tabelle1 alternativ die mappe einzufuegen
reagiert auf zellenwechsel
a1 click > B4+C2 rot ansonsten schwarz
gruss nighty
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
With Worksheet
If Selection.Row = 1 And Selection.Column = 1 Then
Cells(4, 2).Font.ColorIndex = 3
Cells(2, 3).Font.ColorIndex = 3
Else
Cells(4, 2).Font.ColorIndex = 0
Cells(2, 3).Font.ColorIndex = 0
End If
End With
Application.EnableEvents = True
End Sub
Antwort 5 von nighty
hi micha :)
sind bestimmt noch mehr zellen oder :)
schreib mal kurze liste welche zellen anclickbar sein sollen und welche reagieren sollen :)
beispiel
a1=rotschalter fuer c1-c4,f5,h8 usw.
b1=gelbschalter fuer ....
gruss nighty
sind bestimmt noch mehr zellen oder :)
schreib mal kurze liste welche zellen anclickbar sein sollen und welche reagieren sollen :)
beispiel
a1=rotschalter fuer c1-c4,f5,h8 usw.
b1=gelbschalter fuer ....
gruss nighty
Antwort 6 von Micha123
Vielen Dank nighty! ;)
Könnte man noch andere Formatierungen integrieren? Wie zum Beispiel fett?
Und würde es gehen, wenn man nur mit den Mauszeiger über eine Zelle fährt, dass das ganze dann passiert, ne wa?
Nochmals vielen Dank für deine hilfe ;)
Könnte man noch andere Formatierungen integrieren? Wie zum Beispiel fett?
Und würde es gehen, wenn man nur mit den Mauszeiger über eine Zelle fährt, dass das ganze dann passiert, ne wa?
Nochmals vielen Dank für deine hilfe ;)
Antwort 7 von nighty
hi micha :)
fast genauso :)
gruss nighty
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
With Worksheet
If Selection.Row = 1 And Selection.Column = 1 Then
Cells(4, 2).Font.Bold = True
Cells(2, 3).Font.Bold = True
Else
Cells(4, 2).Font.Bold = False
Cells(2, 3).Font.Bold = False
End If
End With
Application.EnableEvents = True
End Sub
fast genauso :)
gruss nighty
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
With Worksheet
If Selection.Row = 1 And Selection.Column = 1 Then
Cells(4, 2).Font.Bold = True
Cells(2, 3).Font.Bold = True
Else
Cells(4, 2).Font.Bold = False
Cells(2, 3).Font.Bold = False
End If
End With
Application.EnableEvents = True
End Sub
Antwort 8 von nighty
hi micha :)
hier noch was zum teufteln :)
meherere bereiche die fett werden sollen
gruss nighty
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
With Worksheet
rem achte auf die 2,ist anzahl bereiche
Dim index(2, 1)
rem erste bereich zeile
index(0, 0) = 1
rem erste bereich spalte
index(0, 1) = 1
usw.
index(1, 0) = 1
index(1, 1) = 2
index(2, 0) = 1
index(2, 1) = 3
rem achte auf die 2,ist anzahl bereiche
For i1 = 0 To 2
If Selection.Row = 1 And Selection.Column = 1 Then
Cells(index(i1, 0), index(i1, 1)).Font.Bold = True
Else
Cells(index(i1, 0), index(i1, 1)).Font.Bold = False
End If
Next i1
End With
Application.EnableEvents = True
End Sub
hier noch was zum teufteln :)
meherere bereiche die fett werden sollen
gruss nighty
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
With Worksheet
rem achte auf die 2,ist anzahl bereiche
Dim index(2, 1)
rem erste bereich zeile
index(0, 0) = 1
rem erste bereich spalte
index(0, 1) = 1
usw.
index(1, 0) = 1
index(1, 1) = 2
index(2, 0) = 1
index(2, 1) = 3
rem achte auf die 2,ist anzahl bereiche
For i1 = 0 To 2
If Selection.Row = 1 And Selection.Column = 1 Then
Cells(index(i1, 0), index(i1, 1)).Font.Bold = True
Else
Cells(index(i1, 0), index(i1, 1)).Font.Bold = False
End If
Next i1
End With
Application.EnableEvents = True
End Sub
Antwort 9 von nighty
hi micha :)
oder so auch mit bereichsangaben :)
gruss nighty
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
With Worksheet
If Selection.Row = 1 And Selection.Column = 1 Then
rem $A$1:$A$3 heisst von ,bis
rem $B$1 einzelbereich
Range("$A$1:$A$3,$B$1").Font.Bold = True
Else
Range("$A$1:$A$3,$B$1").Font.Bold = False
End If
End With
Application.EnableEvents = True
End Sub
oder so auch mit bereichsangaben :)
gruss nighty
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
With Worksheet
If Selection.Row = 1 And Selection.Column = 1 Then
rem $A$1:$A$3 heisst von ,bis
rem $B$1 einzelbereich
Range("$A$1:$A$3,$B$1").Font.Bold = True
Else
Range("$A$1:$A$3,$B$1").Font.Bold = False
End If
End With
Application.EnableEvents = True
End Sub
Antwort 10 von nighty
hi alle :)
was sagt und das :)
es fuehren 1000 wege nach rom :)
gruss nighty
was sagt und das :)
es fuehren 1000 wege nach rom :)
gruss nighty
Antwort 11 von Micha123
Und geht auch beides, also fett und rot gleichzeitig?
Du bist echt gut :)
Du bist echt gut :)
Antwort 12 von nighty
hi micha :)
dann so,eine moeglichkeit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
With Worksheet
If Selection.Row = 1 And Selection.Column = 1 Then
Range("$A$1:$A$3,$B$1").Font.Bold = True
Range("$A$1:$A$3,$B$1").Font.ColorIndex = 3
Else
Range("$A$1:$A$3,$B$1").Font.Bold = False
Range("$A$1:$A$3,$B$1").Font.ColorIndex = 0
End If
End With
Application.EnableEvents = True
End Sub
dann so,eine moeglichkeit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
With Worksheet
If Selection.Row = 1 And Selection.Column = 1 Then
Range("$A$1:$A$3,$B$1").Font.Bold = True
Range("$A$1:$A$3,$B$1").Font.ColorIndex = 3
Else
Range("$A$1:$A$3,$B$1").Font.Bold = False
Range("$A$1:$A$3,$B$1").Font.ColorIndex = 0
End If
End With
Application.EnableEvents = True
End Sub

