Avatar billede Bumle Mester
14. september 2015 - 20:28 Der er 8 kommentarer og
1 løsning

VBA med kant og fyldfarve

Hej derude,

Jeg har fået hjælp til denne VBA, men vil gerne have ændret I den, så jeg kan få kant og andre farver på.
Jeg har prøvet efter bedste formåen, men kan ikke hitte ud af det.

Har denne VBA:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("A4:AN54"), Target) Is Nothing Then
With Target
    Select Case Target.Value
        Case 11 To 20
        .Interior.ColorIndex = 3
        Case 1 To 10
        .Interior.ColorIndex = 4
        Case 21 To 30
        .Interior.ColorIndex = 1
        Case Else
        .Interior.ColorIndex = xlNone
    End Select
End With
End If
End Sub



Og vil gerne have denne farve på:
PatternColorIndex = xlAutomatic
        .Color = 12632256
        .TintAndShade = 0

Herudover så vil jeg gerne have tynd sort kant:
.LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin

Har indtil nu haft denne indspillede macro, men det kører lidt tungt:
Sub Knap3232_Klik()
'
' Knap3232_Klik Makro
'

'
    Range("A4:AN54").Select
    Selection.FormatConditions.Add Type:=xlTextString, String:="01", _
        TextOperator:=xlBeginsWith
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Borders(xlLeft)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlRight)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlTop)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlBottom)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 12632256
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Application.DisplayAlerts = True
    With ThisWorkbook
        .Save
        .Close
    End With
    Application.DisplayAlerts = True
End Sub
Sub Knap3233_Klik()
'
' Knap3233_Klik Makro
'

'
  Range("A4:AN54").Select
  Selection.FormatConditions.Add Type:=xlTextString, String:="11", _
        TextOperator:=xlBeginsWith
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Borders(xlLeft)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlRight)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlTop)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlBottom)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 16751052
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Application.DisplayAlerts = True
    With ThisWorkbook
        .Save
        .Close
    End With
    Application.DisplayAlerts = True
End Sub
Sub Knap3234_Klik()
'
' Knap3234_Klik Makro
'

'
  Range("A4:AN54").Select
  Selection.FormatConditions.Add Type:=xlTextString, String:="21", _
        TextOperator:=xlContains
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Borders(xlLeft)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlRight)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlTop)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlBottom)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 3407718
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
   
    Selection.FormatConditions.Add Type:=xlTextString, String:="31", _
        TextOperator:=xlContains
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Borders(xlLeft)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlRight)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlTop)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlBottom)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 3407718
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Application.DisplayAlerts = True
    With ThisWorkbook
        .Save
        .Close
    End With
    Application.DisplayAlerts = True
End Sub
Sub Knap3235_Klik()
'
' Knap3235_Klik Makro
'

'
  Range("A4:AN54").Select
  Selection.FormatConditions.Add Type:=xlTextString, String:="41", _
        TextOperator:=xlBeginsWith
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Borders(xlLeft)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlRight)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlTop)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlBottom)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 10092543
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False

    Selection.FormatConditions.Add Type:=xlTextString, String:="51", _
        TextOperator:=xlBeginsWith
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Borders(xlLeft)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlRight)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlTop)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlBottom)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 10092543
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Application.DisplayAlerts = True
    With ThisWorkbook
        .Save
        .Close
    End With
    Application.DisplayAlerts = True
End Sub
Sub Knap3236_Klik()
'
' Knap3236_Klik Makro
'

'
  Range("A4:AN54").Select
  Selection.FormatConditions.Add Type:=xlTextString, String:="61", _
        TextOperator:=xlBeginsWith
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Borders(xlLeft)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlRight)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlTop)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlBottom)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 16763904
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False

    Selection.FormatConditions.Add Type:=xlTextString, String:="71", _
        TextOperator:=xlBeginsWith
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Borders(xlLeft)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlRight)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlTop)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlBottom)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 16763904
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Application.DisplayAlerts = True
    With ThisWorkbook
        .Save
        .Close
    End With
    Application.DisplayAlerts = True
End Sub
Sub Knap3237_Klik()
'
' Knap3237_Klik Makro
'

'
  Range("A4:AN54").Select
  Selection.FormatConditions.Add Type:=xlTextString, String:="81", _
        TextOperator:=xlBeginsWith
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Borders(xlLeft)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlRight)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlTop)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlBottom)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent3
        .TintAndShade = 0.599963377788629
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Application.DisplayAlerts = True
    With ThisWorkbook
        .Save
        .Close
    End With
    Application.DisplayAlerts = True
End Sub
Sub Knap3238_Klik()
'
' Knap3238_Klik Makro
'

'
  Range("A4:AN54").Select
Selection.FormatConditions.Add Type:=xlTextString, String:="91", _
        TextOperator:=xlBeginsWith
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Borders(xlLeft)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlRight)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlTop)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Borders(xlBottom)
        .LineStyle = xlContinuous
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 10066431
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Application.DisplayAlerts = True
    With ThisWorkbook
        .Save
        .Close
    End With
    Application.DisplayAlerts = True
End Sub

Macroen er som I kan se også indspillet til, at gemme og lukke min workbook, men det skal VBA ikke gøre.
Skal bare bruge de farver og denne type kant I VBA'en.

Håber, at nogen kan hjælpe mig.
På forhånd tak.
Avatar billede store-morten Ekspert
14. september 2015 - 21:41 #1
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("A4:AN54"), Target) Is Nothing Then
With Target
    Select Case Target.Value
   
        Case 1 To 10
        .Interior.ColorIndex = 4 'celle farve
            With Target.Borders
                .ColorIndex = 1 'ramme farve
                .Weight = xlThin 'ramme tykkelse
                'The available values are xlHairline, xlThin, xlMedium, and xlThick.
            End With
           
        Case 11 To 20
        .Interior.ColorIndex = 3 'celle farve
            With Target.Borders 'ramme farve
                .ColorIndex = 1 'ramme tykkelse
                .Weight = xlThin
                'The available values are xlHairline, xlThin, xlMedium, and xlThick.
            End With
   
        Case 21 To 30
        .Interior.ColorIndex = 1 'celle farve
            With Target.Borders 'ramme farve
                .ColorIndex = 1 'ramme tykkelse
                .Weight = xlThin
                'The available values are xlHairline, xlThin, xlMedium, and xlThick.
            End With
   
        Case Else
        .Interior.ColorIndex = xlNone 'celle farve
            With Target.Borders
                .ColorIndex = xlNone 'ramme farve
            End With
   
    End Select
End With
End If
End Sub
Avatar billede store-morten Ekspert
14. september 2015 - 22:09 #2
Lidt smartere:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("A4:AN54"), Target) Is Nothing Then
With Target
    Select Case Target.Value
   
        Case 1 To 10
        .Interior.ColorIndex = 4 'celle farve
        .Borders.ColorIndex = 1 'ramme farve
        .Borders.Weight = xlThin 'ramme tykkelse
           
        Case 11 To 20
        .Interior.ColorIndex = 3 'celle farve
        .Borders.ColorIndex = 1 'ramme farve
        .Borders.Weight = xlThin 'ramme tykkelse
   
        Case 21 To 30
        .Interior.ColorIndex = 1 'celle farve
        .Borders.ColorIndex = 1 'ramme farve
        .Borders.Weight = xlThin 'ramme tykkelse
   
        Case Else
        .Interior.ColorIndex = xlNone 'celle farve
        .Borders.ColorIndex = xlNone 'ramme farve

    End Select
End With
End If
End Sub
Avatar billede store-morten Ekspert
14. september 2015 - 22:17 #3
Og vil gerne have denne farve på: Color = 12632256

Du har tidliger fået liste over ColorIndex farverne.

Ellers udskiftes ........ColorIndex = 1 med .......Color = 12632256
Avatar billede Bumle Mester
14. september 2015 - 23:14 #4
Hold do kaje, hvor er det bare kanon godt.
Jeg har dog lige en spøjs farvekode som er:
ThemeColor = xlThemeColorAccent6
.TintAndShade = -0.249946592608417

Ved du hvordan jeg lige fikser den?
På forhånd tak

Evt lige sammen med et svar, så du kan få point :-)
Avatar billede store-morten Ekspert
14. september 2015 - 23:59 #5
Mener der er som (ikke testet):

.Interior.ThemeColor = xlThemeColorAccent6
.Interior.TintAndShade = -0.249946592608417

ThemeColor = Gætter på en faveskala (mener det er 1 til 12), som sættes med:
TintAndShade = Graduering fra -1 (Mørkest) til 1 (Lysest)

Bruges i stedet for Interior.ColorIndex som er standard farver.
Avatar billede store-morten Ekspert
15. september 2015 - 00:10 #6
.ThemeColor = xlThemeColorDark1 (whites)
.ThemeColor = xlThemeColorLight1 (blacks)
.ThemeColor = xlThemeColorDark2
.ThemeColor = xlThemeColorLight2
.ThemeColor = xlThemeColorAccent1
.ThemeColor = xlThemeColorAccent2
.ThemeColor = xlThemeColorAccent3
.ThemeColor = xlThemeColorAccent4
.ThemeColor = xlThemeColorAccent5
.ThemeColor = xlThemeColorAccent6
Avatar billede Bumle Mester
15. september 2015 - 00:10 #7
Ok, jeg ser om jeg kan klare mig herfra igen i morgen.
Mange tak for hjælpen.
Avatar billede store-morten Ekspert
15. september 2015 - 02:03 #8
Velbekomme :-)
Avatar billede Bumle Mester
15. september 2015 - 21:18 #9
Virkede i øvrigt perfekt, så jeg er bare ovenud tilpas i dag :-)
1000 tak.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Excel kurser for alle niveauer og behov – find det kursus, der passer til dig

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester