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

كيفية تغيير القيمة بناءً على لون الخلية في Excel؟

تتحدث هذه المقالة عن تغيير قيمة الخلية تلقائيًا بناءً على لون الخلفية في Excel. على سبيل المثال ، إذا كانت الخلايا تملأ باللون الأحمر في التحديد ، فقم بتعبئة هذه الخلايا بالرقم 1 ، ولخلايا لون الخلفية الزرقاء ، املأ الرقم 0.

قم بتغيير القيمة بناءً على لون الخلية باستخدام كود VBA


قم بتغيير القيمة بناءً على لون الخلية باستخدام كود VBA

يمكنك تشغيل رمز VBA أدناه لتغيير القيمة بناءً على لون الخلية في Excel. الرجاء القيام بما يلي.

1. حدد النطاق الذي تريد تغيير القيم بناءً على لون الخلفية ، ثم اضغط قديم + F11 مفاتيح في نفس الوقت لفتح ميكروسوفت فيسوال باسيك للتطبيقات نافذة.

2. في ال ميكروسوفت فيسوال باسيك للتطبيقات الإطار، انقر فوق إدراج > وحدة، ثم انسخ والصق رمز فبا أدناه في نافذة الوحدة النمطية.

كود فبا: قم بتغيير القيمة بناءً على لون الخلية في إكسيل

Sub ChangeValueBasedOnCellColor()
    Dim rg As Range
    Dim xRg As Range
    Set xRg = Selection.Cells
    Application.DisplayAlerts = False
    For Each rg In xRg
        With rg
            Select Case .Interior.Color
                Case Is = 255 'Red
                    .Value = 1
                Case Is = 15773696 'Blue
                    .Value = 0
            End Select
        End With
    Next
    Application.DisplayAlerts = False
End Sub

3. اضغط على F5 مفتاح لتشغيل الكود ، ثم يمكنك رؤية جميع الخلايا الحمراء في النطاق المحدد ممتلئة بالرقم 1 ، ويتم ملء الخلايا الزرقاء بالرقم 0 كما هو موضح أدناه.

 

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

🤖 مساعد 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 (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Is there a way to do this, but have it automatically go through multiple files?
For context, questionnaires were sent to a couple hundred facilities, their MC answer selected corresponds to a color indicating score (e.g. green is good, red is bad), and change the content of the cell (with a process like in this thread) to something that R or another software could read, and then use that to generate automatic reports. I could go through each of these files with this macro (or a completely different idea), but that would take a long time.
This comment was minimized by the moderator on the site
The code works fine for me, but I would need to rewrite the code to fit colours specific for my document. But I don´t know what code "my colours" have, anyone who know where on can find codes for other colours?
This comment was minimized by the moderator on the site
I came across this lucky strike which was helpful but don't know where to find a full directory!
http://cdn-0.access-excel.tips/wp-content/uploads/2015/08/excel_vbcolor_10.png 
This comment was minimized by the moderator on the site
How do you run it, i run but nothing seems to happen
This comment was minimized by the moderator on the site
You can replace colors to values by simply using Find and Replace function. Go to the format function on the right side of the Find and Replace dialog box and then under "Fill" you can select the color that you have. Then on the "replace with" just write the value you want.
This comment was minimized by the moderator on the site
is it possible to adjust this code based on the cells conditional formatting rule?
This comment was minimized by the moderator on the site
Excel seems to crash whenever I try to run the VBA code. Seems like a bust.
This comment was minimized by the moderator on the site
Good day,
The code works well in my case. Can you tell me your Excel version? Thank you for your comment.
This comment was minimized by the moderator on the site
I'm in the same boat, trying to run this but the code seems to get hung. Excel 2016.
This comment was minimized by the moderator on the site
I'm looking to give a cell a name based on the colour within one worksheet. i.e. if a cell is red then it gets named "name", if it is orange then it gets names "surname" etc.



What code would need to change to have the range as the whole sheet/tab and a name instead of a value?
This comment was minimized by the moderator on the site
What changes to the code would be needed if you wanted this to apply to the text color of a cell, rather than the cell color?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations