online 1
gast (50)

/ Forum / Tabellenkalkulation

TabellenkalkulationTabellenkalkulation

Fragevon nok106 vom 27.03.2021, 11:23 Options

Lösung

Makro ändern ??

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


Antwort schreiben

Antwort 1 von fedjo vom 27.03.2021, 19:00 Options

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

Antwort 2 von nok106 vom 28.03.2021, 11:08 Options

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

Antwort 3 von fedjo vom 28.03.2021, 13:28 Options

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

Antwort 4 von nok106 vom 28.03.2021, 14:02 Options

Hallo Fedjo,

noch eine Frage:

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

Mit freundlichem Gruß

Odje

Antwort 5 von fedjo vom 28.03.2021, 14:25 OptionsLösung

Lösung
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

Antwort 6 von nok106 vom 28.03.2021, 14:46 Options

Hallo Fedjo,

Danke .....

Einen schönen Tag noch,

mit freundlichem Gruß

Odje

Ähnliche Themen

IrfanView - Farben ändern eines Bildes
ana  04.07.2008 - 2619 Hits -

Makro
kurtl  10.11.2008 - 77 Hits - 14 Antworten

Makro im Makro deaktivieren ?
korfuweb  02.03.2009 - 179 Hits - 7 Antworten

Makro
Pietro  13.03.2009 - 196 Hits - 1 Antwort

Hinweis

Diese Frage ist schon etwas älter, Sie können daher nicht mehr auf sie antworten. Sollte Ihre Frage noch nicht gelöst sein, stellen Sie einfach eine neue Frage im Forum..

Neue Einträge

Version: supportware 1.9.150 / 10.06.2022, Startzeit:Thu Jan 8 21:07:44 2026