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

كيفية ربط أعمدة الخلايا والحفاظ على لون النص في إكسيل؟

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

اربط أعمدة الخلايا واحتفظ بلون خط النص باستخدام كود VBA


اربط أعمدة الخلايا واحتفظ بلون خط النص باستخدام كود VBA

لإنهاء هذه المهمة في Excel ، قد يكون رمز VBA التالي مفيدًا لك ، يرجى القيام بذلك على النحو التالي:

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

2. انقر إدراج > وحدة، والصق الكود التالي في ملف نافذة الوحدة.

كود فبا: اربط أعمدة الخلايا واحتفظ بلون النص:

Sub MergeFormatCell()
'Updateby Extendoffice
    Dim xSRg As Range
    Dim xDRg As Range
    Dim xRgEachRow As Range
    Dim xRgEach As Range
    Dim xRgVal As String
    Dim I As Integer
    Dim xRgLen As Integer
    Dim xSRgRows As Integer
    Dim xAddress As String
    On Error Resume Next
    xAddress = ActiveWindow.RangeSelection.Address
    Set xSRg = Application.InputBox("Please select cell columns to concatenate:", "KuTools For Excel", xAddress, , , , , 8)
    If xSRg Is Nothing Then Exit Sub
    xSRgRows = xSRg.Rows.Count
    Set xDRg = Application.InputBox("Please select cells to output the result:", "KuTools For Excel", , , , , , 8)
    If xDRg Is Nothing Then Exit Sub
    Set xDRg = xDRg(1)
    For I = 1 To xSRgRows
        xRgLen = 1
        With xDRg.Offset(I - 1)
            .Value = vbNullString
            .ClearFormats
			.NumberFormat = "@"
            Set xRgEachRow = xSRg(1).Offset(I - 1).Resize(1, xSRg.Columns.Count)
            For Each xRgEach In xRgEachRow
                .Value = .Value & Trim(xRgEach.Value) & " "
            Next
            For Each xRgEach In xRgEachRow
                xRgVal = xRgEach.Value
                With .Characters(xRgLen, Len(Trim(xRgVal))).Font
                .Name = xRgEach.Font.Name
                .FontStyle = xRgEach.Font.FontStyle
                .Size = xRgEach.Font.Size
                .Strikethrough = xRgEach.Font.Strikethrough
                .Superscript = xRgEach.Font.Superscript
                .Subscript = xRgEach.Font.Subscript
                .OutlineFont = xRgEach.Font.OutlineFont
                .Shadow = xRgEach.Font.Shadow
                .Underline = xRgEach.Font.Underline
                .ColorIndex = xRgEach.Font.ColorIndex
                End With
                xRgLen = xRgLen + Len(Trim(xRgVal)) + 1
            Next
        End With
    Next I
End Sub

3. ثم اضغط F5 مفتاح لتشغيل هذا الرمز ، ويظهر مربع موجه لتذكيرك بتحديد نطاق البيانات الذي تريد دمجه مع لون النص ، انظر لقطة الشاشة:

4. ثم انقر فوق OK، ظهر مربع حوار آخر ، يرجى تحديد الخلايا التي تريد إخراج النتائج المدمجة فيها ، انظر الصورة:

5. ثم اضغط OK الزر ، فقد تم تجميع الأعمدة دون فقد لون النص كما هو موضح في لقطة الشاشة التالية:

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

🤖 مساعد 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 (14)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi Team,

Thanks a lot for this code! Noticed that it would not take in the text colour if the colour is obtained through conditional formatting. Is there a workaround for it?
This comment was minimized by the moderator on the site
Hello, hack,
I'm sorry, at present, there is no better way to preserve conditional formatting colors when merging cells.

If anyone else has a solution, please share it here as a comment.

Thank you!
This comment was minimized by the moderator on the site
5. Note: If the data which needed to be combine includes numbers, then macro code cannot work correctly.

However, if you insert code:
.NumberFormat = "@"
(after:
.ClearFormats
) betwen 24-25 line numbers, maybe work.
This comment was minimized by the moderator on the site
Hello, Mariusz
Thanks a lot for your comment, it works well. We have updated the code in this article.
Thanks again! 👍
This comment was minimized by the moderator on the site
You're welcome! I like 🥰 the very different and interesting tips on this site.
This comment was minimized by the moderator on the site
thanks for the code!
Can it be automatically update the concatenate column if any change make?
This comment was minimized by the moderator on the site
Hi, Kathy,
Sorry, at present, there is no good way for doing that, you need to run the code again after changing the cell content. 😂
Thank you!
This comment was minimized by the moderator on the site
Alright, thanks for your reply
This comment was minimized by the moderator on the site
Thanks for the code.
If the text has "( )",  for example "tomate (tomates)". It doesn't work as well. Is there something to modify in order to work with "( ) "?
This comment was minimized by the moderator on the site
Hello Rah,
How are you? If the text has "( )", we don't need to change the VBA code. Please see the screenshot, the text "tomato (tomatoes)" can be successfully combined with other cell columns into one column. Hope it may help you.
Sincerely,
Mandy
This comment was minimized by the moderator on the site
Habría manera de hacerlo con números?
This comment was minimized by the moderator on the site
Fantástica la macro de concatenar cadena de texto conservando formato de origen. En mi caso no funcionaba con F5, pero en la pestaña macro, modificar y opciones me permite entrar el modo de ejecucion con CTRL+letra y funciona de maravilla. Muchas gracias.
This comment was minimized by the moderator on the site
Hello,
This methods works well, until xRgLen is higher than 255.
It looks this parameter is a byte :-(
How can this limitation been overtaken ?
This comment was minimized by the moderator on the site
This code works really well. But, how do I add space before or after the text?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations