Keep source formatting when pasting ranges to a shape

Mads_BDP

New Member
Joined
Aug 24, 2020
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Hi all

I have a workbook with 2 different worksheets. In the first worksheet you type in different information. When clicking on the other worksheet the data from the first worksheet is then copied and pasted into shapes in the second worksheet.
I have a challenge of keeping the source formatting when pasting the ranges into my shape. I want some of the ranges to be bold and the other should just stay as they are.

In the below I have highlighted the ranges that I want to be bold and my code:

Private Sub CopySparring(ShtSrc As Worksheet, ShtDst As Worksheet)
Dim shp As Shape

With ShtSrc

ShtDst.Shapes("Sparring").TextFrame.Characters.Text = _
Range("Strength") & Chr(13) _
& .Range("Sparring_Str") & Chr(13) & Chr(13) _
& .Range("Devel") & Chr(13) _
& .Range("Sparring_Dev") & Chr(13) & Chr(13) _
& .Range("Overall_Eva") & Chr(13) _
& .Range("Overall_feedback")

End With

Set shp = ShtDst.Shapes("Sparring")
ChangeFont shp

End Sub

I hope someone can help me.

Thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub CopySparring(ShtSrc As Worksheet, ShtDst As Worksheet)
   With ShtDst.Shapes("Sparring").TextFrame
      .Characters.Font.Bold = False
      .Characters.Text = _
         ShtSrc.Range("Strength") & Chr(13) _
         & ShtSrc.Range("Sparring_Str") & Chr(13) & Chr(13) _
         & ShtSrc.Range("Devel") & Chr(13) _
         & ShtSrc.Range("Sparring_Dev") & Chr(13) & Chr(13) _
         & ShtSrc.Range("Overall_Eva") & Chr(13) _
         & ShtSrc.Range("Overall_feedback")
      .Characters(1, Len(ShtSrc.Range("Strength"))).Font.Bold = True
      .Characters(Len(ShtSrc.Range("Strength")) + Len(ShtSrc.Range("Sparring_Str")) + 4, Len(ShtSrc.Range("Devel"))).Font.Bold = True
   End With
End Sub
 
Upvote 0
Thank you!

It is working perfect for the 2 first ranges (Strength and Sparring_Str) but the last range does not format as bold?
 
Upvote 0
That's because I left you to do the last part. ;)
 
Upvote 0
Upvote 0
Hi again

I tried below:

With ShtDst.Shapes("Sparring").TextFrame
.Characters.Font.Bold = False
.Characters.Text = _
ShtSrc.Range("Strength") & Chr(13) _
& ShtSrc.Range("Sparring_Str") & Chr(13) & Chr(13) _
& ShtSrc.Range("Devel") & Chr(13) _
& ShtSrc.Range("Sparring_Dev") & Chr(13) & Chr(13) _
& ShtSrc.Range("Overall_Eva") & Chr(13) _
& ShtSrc.Range("Overall_feedback")
.Characters(1, Len(ShtSrc.Range("Strength"))).Font.Bold = True
.Characters(Len(ShtSrc.Range("Strength")) + Len(ShtSrc.Range("Sparring_Str")) + 4, Len(ShtSrc.Range("Devel"))).Font.Bold = True
.Characters(Len(ShtSrc.Range("Strength")) + Len(ShtSrc.Range("Sparring_Str")) + Len(ShtSrc.Range("Devel")) + 4, Len(ShtSrc.Range("Overall_Eva"))).Font.Bold = True
End With

But this formats completely random from Devel and down. I can't sort it out - can you please give me an hint?
 
Upvote 0
You need to add the length of the "Sparring_Dev" range as you don't want that to be bold & change the 4 to 7 (it's the number of carriage returns +1)
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,985
Members
452,540
Latest member
haasro02

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top