Ga naar hoofdinhoud

Hoe rasterlijnen te behouden tijdens het vullen van kleur in Excel?

Zoals we allemaal weten, worden de rasterlijnen bij het vullen van de achtergrondkleur in cellen ook bedekt, in dit geval, hoe kunnen we de rasterlijnen behouden terwijl we de achtergrondkleur in Excel-cellen vullen om de volgende schermafbeelding te laten zien.

doc behouden rasterlijnen vulkleur 1

Behoud rasterlijnen terwijl u kleur vult met VBA-code


pijl blauw rechts bel Behoud rasterlijnen terwijl u kleur vult met VBA-code

Normaal gesproken is er voor ons geen directe manier om deze taak op te lossen, maar hier kan ik een VBA-code voor u introduceren. Ga als volgt te werk:

1. Houd de ALT + F11 toetsen om de te openen Microsoft Visual Basic voor toepassingen venster.

2. Links Project-VBAProject dubbelklik op het paneel Dit Werkboek onder de uitgebreide VBA-project, kopieer en plak vervolgens de volgende VBA-code in de lege module:

VBA-code: behoud rasterlijnen tijdens het vullen van kleur

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 behouden rasterlijnen vulkleur 2

3. En sla vervolgens het codevenster op en sluit het, nu, wanneer u een kleur vult voor een reeks cellen, worden de rasterlijnen automatisch weergegeven.

Beste Office-productiviteitstools

馃 Kutools AI-assistent: Een revolutie teweegbrengen in de data-analyse op basis van: Intelligente uitvoering   |  Genereer code  |  Aangepaste formules maken  |  Analyseer gegevens en genereer grafieken  |  Roep Kutools-functies aan...
Populaire functies: Zoek, markeer of identificeer duplicaten   |  Verwijder lege rijen   |  Combineer kolommen of cellen zonder gegevens te verliezen   |   Ronde zonder formule ...
Super opzoeken: Meerdere criteria VLookup    VLookup met meerdere waarden  |   VOpzoeken over meerdere bladen   |   Fuzzy opzoeken ....
Geavanceerde vervolgkeuzelijst: Maak snel een vervolgkeuzelijst   |  Afhankelijke vervolgkeuzelijst   |  Multi-select vervolgkeuzelijst ....
Kolom Beheerder: Voeg een specifiek aantal kolommen toe  |  Kolommen verplaatsen  |  Schakel de zichtbaarheidsstatus van verborgen kolommen in  |  Vergelijk bereiken en kolommen ...
Uitgelichte functies: Raster focus   |  Ontwerpweergave   |   Grote formulebalk    Werkmap- en bladbeheer   |  resource Library (Auto-tekst)   |  Datumkiezer   |  Combineer werkbladen   |  Cellen coderen/decoderen    Stuur e-mails per lijst   |  Super filter   |   Speciaal filter (filter vet/cursief/doorhalen...) ...
Top 15 gereedschapsets12 Tekst Tools (toe te voegen tekst, Tekens verwijderen, ...)   |   50+ tabel Types (Gantt Chart, ...)   |   40+ Praktisch Formules (Bereken leeftijd op basis van verjaardag, ...)   |   19 Invoeging Tools (QR-code invoegen, Afbeelding invoegen vanaf pad, ...)   |   12 Camper ombouw Tools (Getallen naar woorden, Currency Conversion, ...)   |   7 Samenvoegen en splitsen Tools (Geavanceerd Combineer rijen, Gespleten cellen, ...)   |   ... en meer

Geef uw Excel-vaardigheden een boost met Kutools voor Excel en ervaar effici毛ntie als nooit tevoren. Kutools voor Excel biedt meer dan 300 geavanceerde functies om de productiviteit te verhogen en tijd te besparen.  Klik hier om de functie te krijgen die u het meest nodig heeft...

Omschrijving


Office-tabblad Brengt een interface met tabbladen naar Office en maakt uw werk veel gemakkelijker

  • Schakel bewerken en lezen met tabbladen in Word, Excel, PowerPoint in, Publisher, Access, Visio en Project.
  • Open en maak meerdere documenten in nieuwe tabbladen van hetzelfde venster in plaats van in nieuwe vensters.
  • Verhoogt uw productiviteit met 50% en vermindert honderden muisklikken voor u elke dag!
Comments (19)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Is this universally and automatically applied to new tables or sheets opened? Or need to do this for each table or sheet you want to have it? How to make it universally and automatically applied to new tables or sheets?
This comment was minimized by the moderator on the site
Simply change MS Office to Open Office...
This comment was minimized by the moderator on the site
Danke f眉r den super Tipp!
This comment was minimized by the moderator on the site
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....
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
Very helpful- thank you
This comment was minimized by the moderator on the site
This helped me SO much. I have literally been searching so many places and this is the only explanation that worked! Thank you!!!
This comment was minimized by the moderator on the site
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 .
This comment was minimized by the moderator on the site
Thank you!!
This comment was minimized by the moderator on the site
Cool, but now if I fill some cells, and hit Ctrl+Z to undo, it won't work. Will not undo.
This comment was minimized by the moderator on the site
Hello, Andrew,
Yes, the above code can not support Undo feature, you should fill no color manually to undo your work.
Thank you!
This comment was minimized by the moderator on the site
use only standard colors ;)
This comment was minimized by the moderator on the site
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..
This comment was minimized by the moderator on the site
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..
This comment was minimized by the moderator on the site
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?
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
Hi, Vic,
There is no this problem in my Excel workbook, which Excel version do you use?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations