Hello Excel Experts,
Below VBA was posted by Mr Rick Rothstein
I want some change in this below VB. If any cell from A to Z contains a formula like =Sheet1!A5&" "&Sheet1!C7 or =Sheet1!A5*3 etc it shows Runtime error '1004. How to solve this error.
Code:
Sub ConcatWithStyles()
Dim X As Long, Cell As Range, Text As String, Position As Long
Range("A3").Value = Space(Evaluate("SUM(LEN(A1:Z1))+COLUMNS(A1:Z1)-1"))
Position = 1
Application.ScreenUpdating = False
For Each Cell In Range("A1:Z1")
With Range("A3")
.Characters(Position, Len(Cell.Value)).Text = Cell.Characters(1, Len(Cell.Value)).Text
For X = 1 To Len(Cell.Value)
With .Characters(Position + X - 1, 1).Font
.Name = Cell.Characters(X, 1).Font.Name
.Size = Cell.Characters(X, 1).Font.Size
.Bold = Cell.Characters(X, 1).Font.Bold
.Italic = Cell.Characters(X, 1).Font.Italic
.Underline = Cell.Characters(X, 1).Font.Underline
.Color = Cell.Characters(X, 1).Font.Color
.Strikethrough = Cell.Characters(X, 1).Font.Strikethrough
.Subscript = Cell.Characters(X, 1).Font.Subscript
.Superscript = Cell.Characters(X, 1).Font.Superscript
.TintAndShade = Cell.Characters(X, 1).Font.TintAndShade
.FontStyle = Cell.Characters(X, 1).Font.FontStyle
End With
Next
End With
Position = Position + Len(Cell.Value) + 1
Next
Application.ScreenUpdating = True
End Sub
Thanks in advance
Bookmarks