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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,969
Office Version
  1. 365
Platform
  1. Windows
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
 

Mads_BDP

New Member
Joined
Aug 24, 2020
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Thank you!

It is working perfect for the 2 first ranges (Strength and Sparring_Str) but the last range does not format as bold?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,969
Office Version
  1. 365
Platform
  1. Windows
That's because I left you to do the last part. ;)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,969
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Cross posted Keep source formatting when copying range in to shape - OzGrid Free Excel/VBA Help Forum

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 

Mads_BDP

New Member
Joined
Aug 24, 2020
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
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?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,969
Office Version
  1. 365
Platform
  1. Windows
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)
 

Watch MrExcel Video

Forum statistics

Threads
1,130,315
Messages
5,641,482
Members
417,211
Latest member
loadius

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
Top