Note: The other languages of the website are Google-translated. Back to English
Log på  \/ 
x
or
x
Tilmeld  \/ 
x

or

Hvordan bevares gitterlinjer, mens du udfylder farve i Excel?

Som vi alle vidste, når vi udfylder baggrundsfarve til celler, dækkes gitterlinjerne også, i dette tilfælde hvordan kunne vi holde gitterlinjerne, mens vi udfylder baggrundsfarve i Excel-celler for at få vist følgende skærmbillede.

doc holder gitterlinjer fyld farve 1

Bevar gitterlinjer, mens du udfylder farve med VBA-kode


pil blå højre boble Bevar gitterlinjer, mens du udfylder farve med VBA-kode


Normalt er der ingen direkte måde for os at løse dette job på, men her kan jeg introducere en VBA-kode til dig. Gør følgende:

1. Hold nede ALT + F11 nøgler til at åbne Microsoft Visual Basic til applikationer vindue.

2. I venstre side Project-VBAProject dobbeltklik på ruden ThisWorkbook under den udvidede VBAProject, kopier og indsæt derefter følgende VBA-kode i det tomme modul:

VBA-kode: Bevar gitterlinjer, mens du udfylder farve

Dim xRgPre As Range
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    On Error Resume Next
    If Not xRgPre Is Nothing Then DrawBorders xRgPre
    Set xRgPre = Target
End Sub
Private Sub DrawBorders(ByVal Rg As Range)
'Updateby Extendoffice 20160725
    Dim xCell As Range
    Application.ScreenUpdating = False
    For Each xCell In Rg
        If xCell.Interior.ColorIndex = xlNone Then
            With xCell.Borders
                If .ColorIndex = 15 Then
                    .LineStyle = xlNone
                End If
            End With
        Else
            With xCell.Borders
                If .LineStyle = xlNone Then
                    .Weight = xlThin
                    .ColorIndex = 15
                End If
            End With
        End If
    Next
    Application.ScreenUpdating = True
End Sub

doc holder gitterlinjer fyld farve 2

3. Og gem derefter og luk kodevinduet, når du nu udfylder en farve til en række celler, vises gitterlinjerne automatisk.


De bedste Office-produktivitetsværktøjer

Kutools til Excel løser de fleste af dine problemer og øger din produktivitet med 80%

  • Genbruge: Indsæt hurtigt komplekse formler, diagrammer og alt, hvad du har brugt før; Krypter celler med adgangskode Opret postliste og send e-mails ...
  • Super Formula Bar (let redigere flere linjer med tekst og formel); Læsning Layout (let at læse og redigere et stort antal celler); Indsæt til filtreret rækkevidde...
  • Flet celler / rækker / kolonner uden at miste data; Split celler indhold; Kombiner duplikerede rækker / kolonner... Forhindre duplikerede celler; Sammenlign områder...
  • Vælg Duplicate eller Unique Rækker; Vælg tomme rækker (alle celler er tomme); Super Find og Fuzzy Find i mange arbejdsbøger; Tilfældig valg ...
  • Præcis kopi Flere celler uden at ændre formelreference; Auto Opret referencer til flere ark; Indsæt kugler, Afkrydsningsfelter og mere ...
  • Uddrag tekst, Tilføj tekst, Fjern efter position, Fjern mellemrum; Opret og udskriv personsøgningssubtotaler; Konverter mellem celler indhold og kommentarer...
  • Superfilter (gem og anvend filterskemaer på andre ark); Avanceret sortering efter måned / uge / dag, hyppighed og mere; Specielt filter af fed, kursiv ...
  • Kombiner arbejdsbøger og arbejdsark; Fletabeller baseret på nøglekolonner; Opdel data i flere ark; Batch Konverter xls, xlsx og PDF...
  • Mere end 300 kraftfulde funktioner. Understøtter Office / Excel 2007-2019 og 365. Understøtter alle sprog. Nem implementering i din virksomhed eller organisation. Fuld funktioner 30-dages gratis prøveperiode. 60-dages pengene tilbage garanti.
kte-fane 201905

Fanen Office bringer en grænseflade til et kontor med Office, og gør dit arbejde meget lettere

  • Aktiver redigering og læsning af faner i Word, Excel, PowerPoint, Publisher, Access, Visio og Project.
  • Åbn og opret flere dokumenter i nye faner i det samme vindue snarere end i nye vinduer.
  • Øger din produktivitet med 50% og reducerer hundredvis af museklik for dig hver dag!
officetab bund
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    sculbertson1106 · 2 months ago
    This works great. (Thanks)  But here's the real question - Why does Excel allow gridlines to disappear when filling cells with color in the first place? Just another dumb glitch in the techy world that so-called intelligent developers never think of. I mean, the gridlines, by default are supposed to be there anyway...so....
  • To post as a guest, your comment is unpublished.
    Chad · 1 years ago
    Thank you! I was pulling hairs trying to get the nice grey-ish borders to stay after colorizing. Can't believe Microsoft hasn't already implemented this.
  • To post as a guest, your comment is unpublished.
    Alissa · 2 years ago
    Another fix, if you don't want to mess with code:
    First figure out which color gray matches the default lines and have it in mind.
    In the Home tab click Cell styles, right click on Normal, click Modify -> Format -> Border. For Line Color, select that gray. For Presets, select Outline. Done.
    Now you may have to select all (CTRL+A / Command+A) and click Cell styles -> Normal to make sure it's applied to all cells. When you fill a cell, the borders will remain.
    • To post as a guest, your comment is unpublished.
      JL · 9 months ago
      This helped me SO much. I have literally been searching so many places and this is the only explanation that worked! Thank you!!!
    • To post as a guest, your comment is unpublished.
      Fox · 1 years ago
      Alissa , I had the same problem couldn`t get it fixed but your reply helped me a lot , so thank you very much , you are genius .
    • To post as a guest, your comment is unpublished.
      Armaan Sandhu · 2 years ago
      Thank you!!
  • To post as a guest, your comment is unpublished.
    Andrew · 3 years ago
    Cool, but now if I fill some cells, and hit Ctrl+Z to undo, it won't work. Will not undo.
    • To post as a guest, your comment is unpublished.
      skyyang · 3 years ago
      Hello, Andrew,
      Yes, the above code can not support Undo feature, you should fill no color manually to undo your work.
      Thank you!
  • To post as a guest, your comment is unpublished.
    barbatus · 3 years ago
    use only standard colors ;)
  • To post as a guest, your comment is unpublished.
    Terry · 3 years ago
    works but one has to correct the error if you see it.
    Dim xRgPre As Range
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    On Error Resume Next
    If Not xRgPre Is Nothing Then DrawBorders xRgPre
    Set xRgPre = Target


    *************************************
    Should READ... as the If statement only ensures that something is there to set to memory allocation.

    One could set the next line below for clean up and not allow memory leaks.

    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    On Error Resume Next
    Set xRgPre = Target
    If Not xRgPre Is Nothing Then DrawBorders xRgPre
    'For ensured memory leaks do not happen
    'Clean up the memory allocated after it is not needed.
    Set xRqPre = Nothing



    Have a nice day..
    • To post as a guest, your comment is unpublished.
      James Godesky · 1 years ago
      Does not work with Conditional Formatting. Set xRqPre = Nothing gives error: variable not defined (deleted the line).Screen jiggles here too, using 2010. Other wise its a cool tool..
  • To post as a guest, your comment is unpublished.
    Vic · 3 years ago
    Works fine, but sadly every time I now click on a cell, the worksheet judders! Removed the VBA and the judder has ceased. Wonder why this should happen?
    • To post as a guest, your comment is unpublished.
      jdjshark@gmail.com · 2 years ago
      Same here with Excel 2016. I'm getting freezing and mostly blanked out screen for several seconds, especially when selecting many cells. It's a shame because it does work perfectly otherwise.
    • To post as a guest, your comment is unpublished.
      skyyang · 3 years ago
      Hi, Vic,
      There is no this problem in my Excel workbook, which Excel version do you use?
  • To post as a guest, your comment is unpublished.
    dolphinks · 3 years ago
    Fabulous fix!!