·
2 months ago
Great was trying to paind for a good loook of my site presentation https://jpeeiclinic.blogspot.com
眾所周知,當我們為單元格填充背景色時,網格線也會被覆蓋,在這種情況下,如何在填充Excel單元格中的背景色時保持網格線以顯示以下屏幕截圖。
通常,沒有直接的方法可以讓我們解決這個問題,但是,在這裡,我可以為您介紹一個VBA代碼。 請執行以下操作:
1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。
2。 在左邊 項目-VBA項目 窗格,雙擊 的ThisWorkbook 在擴展下 VBA項目,然後將以下VBA代碼複製並粘貼到空白模塊中:
VBA代碼:填充顏色時保留網格線
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
3。 然後保存並關閉代碼窗口,現在,當您為一系列單元格填充顏色時,網格線將自動顯示。