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

كيفية تعيين لون الخلية يساوي لون خلية آخر في إكسيل؟

إذا كنت تريد مطابقة لون خلية بأخرى ، فيمكن أن تساعدك الطريقة الواردة في هذه المقالة.

عيّن لون الخلية مساويًا للون خلية آخر برمز VBA


عيّن لون الخلية مساويًا للون خلية آخر برمز VBA

يمكن أن تساعدك طريقة VBA أدناه في تعيين لون خلية يساوي لون آخر في Excel. الرجاء القيام بما يلي.

1. في ورقة العمل ، تحتاج إلى مطابقة لون خليتين ، يرجى النقر بزر الماوس الأيمن فوق علامة تبويب الورقة ، ثم النقر فوق عرض الرمز من قائمة النقر بزر الماوس الأيمن. انظر لقطة الشاشة:

2. في الافتتاح ميكروسوفت فيسوال باسيك للتطبيقات نافذة ، تحتاج إلى نسخ ولصق كود فبا في نافذة التعليمات البرمجية.

رمز فبا: عيّن لون الخلية مساويًا للون خلية آخر

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Me.Range("C1").Interior.Color = Me.Range("A1").Interior.Color
End Sub

ملاحظات: في الكود ، A1 هي الخلية التي تحتوي على لون التعبئة الذي ستطابقه مع C1. يرجى تغييرها بناءً على احتياجاتك.

ثم يتم ملء الخلية C1 بنفس لون الخلية A1 كما هو موضح أدناه.

من الآن فصاعدًا ، عند تغيير لون التعبئة في A1 ، ستتم مطابقة C1 بنفس اللون تلقائيًا.


مقالات ذات صلة:

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

🤖 مساعد 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 (21)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
не работает ваш код

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("C1").Interior.Color = Me.Range("A1").Interior.Color
End Sub

после его добавления, при смене цвета в ячейке С1, он изменяется на тот цвет, который был
This comment was minimized by the moderator on the site
Hi, I am trying to change come cells to match another that have been conditionally formatted. Your code 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("C1").Interior.Color = Me.Range("A1").DisplayFormat.Interior.Color
End Sub
I adapted to
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("A2:C2").Interior.Color = Me.Range("D2").DisplayFormat.Interior.Color
End Sub

This works fine for just one row.  How do I get this to work in all of the rows I need?  If I repeat the code with the next row
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("A3:C3").Interior.Color = Me.Range("D3").DisplayFormat.Interior.Color
End Sub

Then I get a Compile error: Ambiguous name detected: Worksheet_SelectionChange
I tried having the code asPrivate Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("A2:C10").Interior.Color = Me.Range("D2:D10").DisplayFormat.Interior.ColorEnd Sub

But all the rows just filled black rather than the colours required.  What coding do I need?
This comment was minimized by the moderator on the site
Hi -- I'm having a difficult time using your code. I'm trying to do exactly what you're saying. Make one cell be the same color as another cell (without any values necessary) on the same sheet. Is there something in that code that should be adjusted?
This comment was minimized by the moderator on the site
I've attached a screen shot of the file Im working on - I don't seem to be able to upload a .xlsm file? In this file I have used the original VBA from this thread and can now match the conditionally formatted colour of cell A10 in D10. How can I get this to work on a range of cells? I would like to get the colour of the range of cells A10:A200 to transfer over to D10:D200. Can anyone help please? There is a drop down list in use in the A column but once we have placed an order we need to be able to over type the purchase order number. The items in the list are all set to conditionally format to a colour (eg ORDER OK turns cell green, CLIENT TBC turns cell yellow) but the colour goes blank once the PO has been put in.
This comment was minimized by the moderator on the site
image didn't upload - hopefully attached now....
This comment was minimized by the moderator on the site
Wow - this is great. I hope you can help me adapt your script to my needs. I need to make cells D10:D200 match the conditionally formatted colour of cells A10:A200 - can you help me to get this working please. The cells are all in the same worksheet.
This comment was minimized by the moderator on the site
As Chris I am interested in copying the background color from another worksheet?
This comment was minimized by the moderator on the site
I found your code to 'set cell color to equal to another cell color" and it works when I am using it on the same worksheet ( ex from cell A1 to cell A2). I am wondering if there is a way to have this same functionality from another worksheet (ex to copy cell color from sheet1!A1 to sheet2!A1? Any help you could offer would be appreciated!
This comment was minimized by the moderator on the site
This is a good start to what I am looking to do. But I am looking for something a bit more complicated

How could I adapt this to apply to multiple rows and a range. For instance I have a header column in Column B, I want cells from G to CS to match the colour of the header row but only is they have something in them ie the letter x. I know I can write an IF and THEN statement but how would I apply it to multiple Rows without writing a code for each row.
This comment was minimized by the moderator on the site
Hi Zack,
Sorry can't help you with that. Any question about Excel, please don’t hesitate to post in our forum: https://www.extendoffice.com/forum.html.
This comment was minimized by the moderator on the site
hi , how to apply the same VBA but on a range of cells for example :

i want to have the same color of range (C8:X8) to be apply on the range (S16:AL16) one by one in the same order (S16 get the color of C16 , T16 get the color of D8 ....etc)
This comment was minimized by the moderator on the site
Good day,

The below VBA code can help you solving the problem. Thanks for your comment.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xSRg, xDRg, xISRg, xIDRg As Range
Dim xFNum As Long
On Error Resume Next
Set xSRg = Range("C8:X8")
Set xDRg = Range("S16:AL16")
For xFNum = 1 To xSRg.count
Set xISRg = xSRg.Item(xFNum)
Set xIDRg = xDRg.Item(xFNum)
xIDRg.Interior.Color = xISRg.Interior.Color
Next xFNum
End Sub
This comment was minimized by the moderator on the site
Hi

I am trying to do similar, but I have two spreadsheets (files). Spreadsheet 1 is the Master where the data is manually updated and file (spreadsheet 2) is equalling the data in the same cell as spreadsheet 1. When I open spreadsheet 2, I get a prompt to refresh with spreadsheet 1 no promlems, but if the colour of the cell is changed in spreadsheet 1 it does not update in spreadsheet 2, neither does 'strike-trough' of fonts..help please?
This comment was minimized by the moderator on the site
Hi, the cell being referenced for colour changes colour based on conditional formatting. The above doesn't seem to work with that and the destination cells are staying blank. How can this be corrected? Thanks
This comment was minimized by the moderator on the site
If you have Excel 2010 or later you can use the DisplayFormat function to return the color of a conditionally formatted cell. See below:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Me.Range("C1").Interior.Color = Me.Range("A1").DisplayFormat.Interior.Color
End Sub
This comment was minimized by the moderator on the site
AMAZING... I should have read the comments sooner as I have been struggling for a while to figure this out.
This comment was minimized by the moderator on the site
Hi,Would please write a code to apply conditional formatting from a colum of data to the next column?In colum A, I have a series of data from A1 to A1000 including conditional formatting which applies color in some of the cells. I need to apply those colors to the values in the next column B1 to B1000.
very much appreciated.
This comment was minimized by the moderator on the site
Hi, would it be possible to extend this to a conditional formatting; not to match a color created by conditional format, but if a conditional format condition is matched, that the applied conditional format takes on the color of a specific cell. Trying to use this in a gantt chart, colouring the days between start and end date, but the conditional format that generates the gantt bars, should take the color of the cell that contains the Task (which I set manually)
This comment was minimized by the moderator on the site
can this be done on range of cells or just for a single cell?
This comment was minimized by the moderator on the site
LP you are absolutely AMAZING!!!!!!i was trying for the longest time to get cells to match the conditional formatting background color! you are a lifesaver!!!
This comment was minimized by the moderator on the site
I have the same problem. Works on cells without conditional formatting but doesn't with those that do
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations