Merge contents of 2 Excel cells keeping character format intact (using VBA) -
As the title says, I try to merge the contents of 2 out of 3 cells in Excel. There was a similar question, but those solutions do not have to retain the character. For example, some parts of source cell contents are bold and red formatted, the other parts are normal. When I call them
range ("A3") = range ("A1") and & amp; Range ("A2")
Then any formatting of A1 and A2 is lost. The format that I need is retaining a pattern. This is going to be part of a larger VBA program, so I do not want a VBA solution, no formula, please. Excel version 2002 (XP).
Doctor, this is an interesting question that I was stumped myself, but saw the value, so some After the search, what I have found here is that. From the basic understanding of the formatting I have in the cell, which I've got modified for my use below.
Merge_Cells () Dynamic IOn integer dim RngFrom1 as range Range dim RngFrom2 Range dim RngTo as Range dim as lenFrom1 Integer set as integer lenFrom2 set integer rngFrom1 = Set cells (1, 1) as rngFrom2 = cells (1, 2) set rngTo = cells (1, 3) lenFrom1 = rngFrom1.Characters.Count lenFrom2 = rngFrom2.Characters.Count rngTo. Value = rngFrom1.Text & amp; RngFrom2.Text for IOS = 1 lenFrom1 with rngTo.Characters (iOS, 1) .Font .Name = rngFrom1.Characters (iOS, 1) .fontName .bold = rngFrom1.Characters (iOS, 1) .Font.Bold .Size = rngFrom1.Characters (iOS, 1) .Font.Size .ColorIndex = rngFrom1.Characters (iOS, 1) with rngTo.Characters for IOS = 1 to the next iOS lenFrom2 (lenFrom1 + iOS, 1 .Font.ColorIndex termination) .font .Name = rngFrom2.Characters (iOS, 1) .fontName .bold = rngFrom2.Characters (IOS, 1) .Font.Bold .Size = rngFrom2.Characters (IOS, 1) .Font.Size .ColorIndex = RngFrom2.Can (IOS, 1) .Font.ColorIndex End with Next IOS End SubJust type 3 with your specific cells Replace botany (maybe) Someone might get a cleaner, but when I tested it, then it works as I understand (and I). Hope this will be helpful ...
Comments
Post a Comment