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

كيف تحافظ على تنسيق الخلية أثناء الرجوع إلى خلايا الورقة الأخرى؟

بشكل عام ، تحتفظ الخلية فقط بقيمة الخلية أثناء الرجوع إلى خلية أخرى ، ولكن في هذه المقالة ، أقدم رمز VBA للاحتفاظ بقيم الخلية وتنسيقها أثناء الرجوع إلى خلية أخرى ، وتتغير قيم الخلية وتنسيقها مع تغير الخلية المرجعية على النحو التالي تظهر لقطة الشاشة.
doc يحافظ على التنسيق أثناء الرجوع إلى 1

احتفظ بتنسيق الخلية أثناء الرجوع إلى خلية أخرى باستخدام VBA


احتفظ بتنسيق الخلية أثناء الرجوع إلى خلية أخرى باستخدام VBA

للتعامل مع هذه الوظيفة ، ما عليك سوى تشغيل الكود أدناه.

1. قم بتمكين المصنف الذي تستخدمه ، اضغط على ALT + F11 مفتاح التمكين Microsoft Visual Basic للتطبيق ، وانقر نقرًا مزدوجًا فوق اسم الورقة الذي ستضع فيه الخلية المرجعية مشروع- VBAProject جزء لإظهار برنامج نصي فارغ. في هذه الحالة ، أريد الإشارة إلى الخلية A1 في ال Sheet1. انظر لقطة الشاشة:
doc يحافظ على التنسيق أثناء الرجوع إلى 2

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

فبا: احتفظ بالتنسيق والقيم أثناء الرجوع إلى خلية أخرى

Private Sub Worksheet_Activate()
'UpdatebyExtendoffice20101024
    Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count > 1 Or Target.Value = "" Then Exit Sub
    Application.EnableEvents = False
    If Not Intersect(Target, Range("A1")) Is Nothing Then              'Range("A1") the reference cell
        Target.Copy
        ActiveWorkbook.Sheets("Sheet2").Range("B1").PasteSpecial xlPasteAllUsingSourceTheme
                    'Range("B1")the cell linked to reference cell,ActiveWorkbook.Sheets("Sheet2")the sheet which contains linked cell
        Application.CutCopyMode = False
        Target.Select
    End If
    Application.EnableEvents = True
End Sub

ملاحظات: A1 هي الخلية المرجعية ، B1 in ورقة 2 هي الخلية التي تريد ربطها بالخلية المرجعية والاحتفاظ بالقيم والتنسيق باستخدام A1 في Shee1.

بعد ذلك ، عند تغيير القيم أو التنسيق في الخلية A1 في الورقة 1 ، سيتم تغيير الخلية B1 في الورقة 2 أثناء النقر فوق الخلية المرجعية مرتين.


عد حسب اللون

في بعض الحالات ، قد يكون لديك نطاق من السعرات الحرارية بألوان متعددة ، وما تريده هو حساب / جمع القيم بناءً على نفس اللون ، كيف يمكنك الحساب بسرعة؟
بدافع كوتولس ل إكسيل's عد حسب اللون، يمكنك إجراء العديد من العمليات الحسابية بسرعة حسب اللون ، كما يمكنك إنشاء تقرير بالنتيجة المحسوبة.
عد الوثيقة حسب اللون

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

🤖 مساعد 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 (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello, I would like to keep the format of my reference cell. However, even with your VBA it doesn't work. Can you help me please?
I would like my B2 cell of my sheet 1 to be my reference cell for my C2 cells of sheets 2,3,4,5,6,7.
My document is a list of people, therefore I will have several cells of references not the continuation.
Thanks in advance
This comment was minimized by the moderator on the site
No tienes uno que sea dentro del mismo archivo
This comment was minimized by the moderator on the site
Thanks for sharing this. I have a range of cells in WorksheetA, Sheet1, Range G3:G3000 that I want to reference in WorksheetB, Sheet1, Range G3:G3000. I need WorksheetB, Sheet1, Range G3:G3000 to display both the value and the format of the referenced cells in WorksheetA, Sheet1, G3:G3000. Is there a VBA script that will allow for this?
This comment was minimized by the moderator on the site
Thanks for sharing this. Is there a VBA script that allows for referencing a range of cells in one workbook and then displaying the value and format of the referenced cells in a different workbook?
This comment was minimized by the moderator on the site
Thank you so much for the script. Can you tell me if there is a way for the linked cell to update without having to double click on the reference cell? Thank you!
This comment was minimized by the moderator on the site
hello, I believe this may be just what I am looking for. I need the referenced text to have the same colors and features from the referenced page. The only thing different about mine is that I am pulling from a larger range. I have never used VBA before so I wanted to confirm before I did changes. I am pulling from a document (sheet 2) onto (sheet 1) document. I have used IF formulas to do this, so it returns a value from 3 different columns and they are not in a row. The columns are F,H,J. Could you please help me figure out how I can make this work?
This comment was minimized by the moderator on the site
I am dealing with similar issue. I have a formula in column C, which takes value from the same row, column A. (But only IF B3 is not x AND A3 is not empty):

=IF(B3="x";"y";IF(A3="";"z";A3))

Cells of column A look like this: OK 2019_12_03
But "OK" is in bold format. I would like to keep this format.
I want this for hundreds of cells, so clicking or writing a script for each one of them is undesirable. Any ideas if such feature exists? I'd appreciate some kind of "WITHFORMAT()" function that I could put in the formula, so the following formula would keep the original format:

=IF(B3="x";"y";IF(A3="";"z";WITHFORMAT(A3)))
This comment was minimized by the moderator on the site
Sorry, your problem is a bit complex, I do not understand clearly.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations