Ana içeriğe atla

Excel'de hücre sütunları nasıl birleştirilir ve metin rengi nasıl korunur?

Hepimizin bildiği gibi, hücre sütunlarını bir sütun halinde birleştirirken veya birleştirirken, hücre biçimlendirmesi (metin yazı tipi rengi, sayı biçimlendirmesi vb.) Kaybolacaktır. Bu makalede, hücre sütunlarını tek bir yerde birleştirmek ve metin rengini Excel'de olabildiğince kolay tutmak için bazı püf noktaları tanıtacağım.

Hücre sütunlarını birleştirin ve metin yazı tipi rengini VBA kodu ile koruyun


Hücre sütunlarını birleştirin ve metin yazı tipi rengini VBA kodu ile koruyun

Bu görevi Excel'de bitirmek için aşağıdaki VBA kodu size bir iyilik yapabilir, lütfen şunu yapın:

1. Basılı tutun ALT + F11 tuşlarını açmak için Uygulamalar için Microsoft Visual Basic pencere.

2. tıklayın Ekle > modülve aşağıdaki kodu Modül Penceresi.

VBA kodu: hücre sütunlarını birleştirin ve metin rengini koruyun:

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. Daha sonra tuşuna basın. F5 Bu kodu çalıştırmak için anahtar ve metin rengiyle birleştirmek istediğiniz veri aralığını seçmenizi hatırlatmak için bir istem kutusu açılır, ekran görüntüsüne bakın:

4. Ve sonra tıklayın OK, başka bir iletişim kutusu belirdi, lütfen birleştirilmiş sonuçların çıktısını almak istediğiniz hücreleri seçin, ekran görüntüsüne bakın:

5. Sonra tıklayın OK düğmesi, gösterilen aşağıdaki ekran görüntüsü gibi metin rengini kaybetmeden birleştirildi:

En İyi Ofis Üretkenlik Araçları

🤖 Kutools AI Yardımcısı: Aşağıdakilere dayalı olarak veri analizinde devrim yaratın: Akıllı Yürütme   |  Kodunu oluşturun  |  Özel Formüller Oluşturun  |  Verileri Analiz Edin ve Grafikler Oluşturun  |  Kutools İşlevlerini Çağır...
Popüler Özellikler: Yinelenenleri Bul, Vurgula veya Tanımla   |  Boş Satırları Sil   |  Veri Kaybı Olmadan Sütunları veya Hücreleri Birleştirin   |   Formülsüz Tur ...
Süper Arama: Çoklu Ölçütlü VLookup    Çoklu Değer VLookup  |   Birden Çok Sayfada VLookup   |   Bulanık Arama ....
Gelişmiş Açılır Liste: Hızla Açılır Liste Oluşturun   |  Bağımlı Açılır Liste   |  Çoklu Seçim Açılır Liste ....
Sütun Yöneticisi: Belirli Sayıda Sütun Ekleme  |  Sütunları Taşı  |  Gizli Sütunların Görünürlük Durumunu Değiştir  |  Aralıkları ve Sütunları Karşılaştırın ...
Öne Çıkan Özellikler: Izgara Odağı   |  Tasarım görünümü   |   Büyük Formül Çubuğu    Çalışma Kitabı ve Sayfa Yöneticisi   |  Kaynak Kütüphanesi (Otomatik metin)   |  Tarih Seçici   |  Çalışma Sayfalarını Birleştirin   |  Hücreleri Şifrele/Şifresini Çöz    E-postaları Listeye Göre Gönder   |  Süper Filtre   |   Özel Filtre (kalın/italik/üstü çizili filtre...) ...
En İyi 15 Araç Seti12 Metin Tools (Metin ekle, Karakterleri Kaldır, ...)   |   50+ Grafik Türleri (Gantt şeması, ...)   |   40+ Pratik Formüller (Yaşı doğum gününe göre hesapla, ...)   |   19 sokma Tools (QR Kodunu Girin, Yoldan Resim Ekle, ...)   |   12 Dönüştürme Tools (Sayılardan Kelimelere, Para Birimi Dönüştürme, ...)   |   7 Birleştir ve Böl Tools (Gelişmiş Kombine Satırları, Bölünmüş hücreler, ...)   |   ... ve dahası

Kutools for Excel ile Excel Becerilerinizi Güçlendirin ve Daha Önce Hiç Olmadığı Gibi Verimliliği Deneyimleyin. Kutools for Excel, Üretkenliği Artırmak ve Zamandan Tasarruf Etmek için 300'den Fazla Gelişmiş Özellik Sunar.  En Çok İhtiyacınız Olan Özelliği Almak İçin Buraya Tıklayın...

Açıklama


Office Tab, Office'e Sekmeli Arayüz Getirir ve İşinizi Çok Daha Kolay Hale Getirir

  • Word, Excel, PowerPoint'te sekmeli düzenlemeyi ve okumayı etkinleştirin, Publisher, Access, Visio ve Project.
  • Yeni pencereler yerine aynı pencerenin yeni sekmelerinde birden çok belge açın ve oluşturun.
  • Üretkenliğinizi% 50 artırır ve her gün sizin için yüzlerce fare tıklamasını azaltır!
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