1.6k Aufrufe
Gefragt in Tabellenkalkulation von nok106 Einsteiger_in (71 Punkte)
Hallo Excelfreunde !

Gibt es hierfür eine Lösung?

Besteht die Möglichkeit das folgende Makro so zu ändern,
dass man verschiedene Tabellenbereiche damit markieren könnte?

Sub ZeilenEinfaerben()
Dim Start As Long
Dim Ende As Long
Dim Lcol As Integer
Dim Farbe As Integer
Dim i As Long
Start = Application.InputBox("Wo soll das Einfärben beginnen?", _
"Start", Type:=1)
Ende = Application.InputBox("Wo soll das Einfärben" _
& " enden werden?", "Ende", Type:=1)
Lcol = Application.InputBox("Wieviele Spalten" _
& " sollen eingefärbt werden?", _
"Breite in Spalten", Type:=1)
Farbe = Application.InputBox("Welche Farbe soll " _
& "verwendet werden?", "Farbe", Type:=1)
For i = Start To Ende Step 2
Range(Cells(i, 1), Cells(i, Lcol)) _
.Interior.ColorIndex = Farbe
Next
End Sub

Hat jemand eine Idee ob das geht und wenn ja - Wie ?

Einstweilen herzlichen Dank an alle, die sich für mich bemühen.

MfG
Odje

6 Antworten

0 Punkte
Beantwortet von
Hallo Odje,
Tabellenbereiche könnte man so markieren :

Option Explicit
Sub Bereich()
Dim Rng As Range
On Error Resume Next
Set Rng = Range("A1")
Set Rng = Application.InputBox(Prompt:="Einfärben z.B.: ( A5:B10;E1:F4 )", Type:=8)
If Rng Is Nothing Then
MsgBox "Operation Cancelled"
Else
Rng.Select
End If
End Sub

Gruß
fedjo
0 Punkte
Beantwortet von nok106 Einsteiger_in (71 Punkte)
Hallo Fedjo,

für deine Antwort herzlichen Dank.

Habe mal meine Vorstellung mit dem Rekorder aufgezeichnet.
Wie würde der Code in der VBA-Sprache aussehen?

Sub Zeilen_färben()
Application.ScreenUpdating = False
Range("A3:C43,E3:G43").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=REST(ZEILE();2)=0"
Selection.FormatConditions(1).Interior.ColorIndex = 36
Range("A1").Select
Application.ScreenUpdating = True
End Sub

Mit freundlichem Gruß

Odje
0 Punkte
Beantwortet von
Hi Odje,
versuchs mal so:

Option Explicit
Sub Bereich()
Application.ScreenUpdating = False
Dim Rng As Range
On Error Resume Next
Set Rng = Range("A1")
Set Rng = Application.InputBox(Prompt:="Einfärben z.B.: ( A5:B10;E1:F4 )", Type:=8)
If Rng Is Nothing Then
MsgBox "Operation Cancelled"
Else
Rng.Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=REST(ZEILE();2)=0"
Selection.FormatConditions(1).Interior.ColorIndex = 36
Range("A1").Select
Application.ScreenUpdating = True
End If
End Sub

Gruß
fedjo
0 Punkte
Beantwortet von nok106 Einsteiger_in (71 Punkte)
Hallo Fedjo,

noch eine Frage:

Was bedeutet (bewirkt) im Code die AngabeType:=1 bzw. Type:=8 ?

Mit freundlichem Gruß

Odje
0 Punkte
Beantwortet von
Hallo Odje

Wird das Type-Argument auf 8 gesetzt, gibt InputBox ein Range-Objekt zurück.
Inputbox mit Type 1 laesst nur Zahlen als Eingabe zu.

Gruß
fedjo
0 Punkte
Beantwortet von nok106 Einsteiger_in (71 Punkte)
Hallo Fedjo,

Danke .....

Einen schönen Tag noch,

mit freundlichem Gruß

Odje
...