انتقل إلى المحتوى الرئيسي

كيفية الحفاظ على خطوط الشبكة أثناء ملء اللون في Excel؟

كما نعلم جميعًا ، عندما نملأ لون الخلفية بالخلايا ، ستتم تغطية خطوط الشبكة أيضًا ، في هذه الحالة ، كيف يمكننا الاحتفاظ بخطوط الشبكة أثناء ملء لون الخلفية في خلايا Excel للحصول على لقطة الشاشة التالية الموضحة.

doc احتفظ بخطوط الشبكة بلون التعبئة 1

احتفظ بخطوط الشبكة أثناء تعبئة اللون برمز VBA


السهم الأزرق الحق فقاعة احتفظ بخطوط الشبكة أثناء تعبئة اللون برمز VBA

في العادة ، لا توجد طريقة مباشرة لحل هذه الوظيفة ، ولكن هنا ، يمكنني تقديم رمز VBA لك. الرجاء القيام بما يلي:

1. اضغط باستمرار على ALT + F11 مفاتيح لفتح ميكروسوفت فيسوال باسيك للتطبيقات نافذة.

2. في اليسار مشروع- VBAProject جزء ، انقر نقرًا مزدوجًا ThisWorkbook تحت الموسعة مشروع VBAP، ثم انسخ والصق رمز فبا التالي في الوحدة النمطية الفارغة:

كود فبا: الحفاظ على خطوط الشبكة أثناء ملء اللون

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 احتفظ بخطوط الشبكة بلون التعبئة 2

3. ثم قم بحفظ وإغلاق نافذة التعليمات البرمجية ، الآن ، عندما تقوم بملء لون لمجموعة من الخلايا ، سيتم عرض خطوط الشبكة تلقائيًا.

أفضل أدوات إنتاجية المكتب

🤖 مساعد Kutools AI: إحداث ثورة في تحليل البيانات على أساس: التنفيذ الذكي   |  إنشاء التعليمات البرمجية  |  إنشاء صيغ مخصصة  |  تحليل البيانات وإنشاء الرسوم البيانية  |  استدعاء وظائف Kutools...
الميزات الشعبية: البحث عن التكرارات أو تمييزها أو تحديدها   |  حذف الصفوف الفارغة   |  دمج الأعمدة أو الخلايا دون فقدان البيانات   |   جولة بدون صيغة 
سوبر بحث: معايير متعددة VLookup    VLookup ذات القيمة المتعددة  |   VLookup عبر أوراق متعددة   |   بحث غامض ....
قائمة منسدلة متقدمة: إنشاء القائمة المنسدلة بسرعة   |  القائمة المنسدلة التابعة   |  قائمة منسدلة متعددة التحديد ....
مدير العمود: إضافة عدد محدد من الأعمدة  |  نقل الأعمدة  |  تبديل حالة رؤية الأعمدة المخفية  |  مقارنة النطاقات والأعمدة 
الميزات المميزة: التركيز على الشبكة   |  عرض تصميم   |   شريط الفورمولا الكبير    مدير المصنفات والأوراق   |  مكتبة الموارد (النص السيارات)   |  منتقي التاريخ   |  اجمع أوراق العمل   |  تشفير/فك تشفير الخلايا    إرسال رسائل البريد الإلكتروني عن طريق القائمة   |  سوبر تصفية   |   مرشح خاص (تصفية غامق / مائل / يتوسطه خط ...) ...
أفضل 15 مجموعة أدوات12 نص الأدوات (إضافة نص, إزالة الأحرف، ...)   |   +50 رسم الأنواع (مخطط جانت، ...)   |   40+ عملي الصيغ (احسب العمر على أساس تاريخ الميلاد، ...)   |   19 إدخال الأدوات (أدخل رمز الاستجابة السريعة, إدراج صورة من المسار، ...)   |   12 تحويل الأدوات (أرقام إلى كلمات, نتيجة تحويل عملة، ...)   |   7 دمج وتقسيم الأدوات (الجمع بين الصفوف المتقدمة, تقسيم الخلايا، ...)   |   ... و اكثر

عزز مهاراتك في Excel باستخدام Kutools for Excel، واختبر كفاءة لم يسبق لها مثيل. يقدم Kutools for Excel أكثر من 300 ميزة متقدمة لتعزيز الإنتاجية وتوفير الوقت.  انقر هنا للحصول على الميزة التي تحتاجها أكثر...

الوصف


يجلب Office Tab الواجهة المبوبة إلى Office ، ويجعل عملك أسهل بكثير

  • تمكين التحرير والقراءة المبوبة في Word و Excel و PowerPointوالناشر والوصول و Visio والمشروع.
  • فتح وإنشاء مستندات متعددة في علامات تبويب جديدة من نفس النافذة ، بدلاً من النوافذ الجديدة.
  • يزيد من إنتاجيتك بنسبة 50٪ ، ويقلل مئات النقرات بالماوس كل يوم!
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