Insert text (add to) existing text in a cell

JamesPTuttle

New Member
Joined
Mar 19, 2004
Messages
17
Hello

Can someone point me in the right direction on how I would fix this macro ?

As a macro CTRL k

In the current active cell - add " (XYZ) " in bold to the end of what ever is already in the cell. Please bear in mind that some cells have several lines of text - so I will need to make sure that as part of the macro, it goes to the very bottom of the cell text prior to inserting the " (XYZ) '

I attached my starting code below - It seems to work however it aways inserts the original text the macro was recorded with, and replaces what current text is in the active cell


Sub Macro3()
'
' Keyboard Shortcut: Ctrl+k
'
ActiveCell.FormulaR1C1 = "This is a test (XYZ)"
With ActiveCell.Characters(Start:=1, Length:=19).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
With ActiveCell.Characters(Start:=20, Length:=5).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("I471").Select
End Sub



THANKS for any assistance

James
 

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.
Will the line
ActiveCell=ActiveCell & "XYZ"
do what you want?
 
Upvote 0
Hi James,
To enter the (XYZ) onto the end of the value in the cell (say D15) you can use this.
[D15].Value = [D15].Value & " (XYZ)"
This help?
 
Upvote 0
As I am vb illiterate, can you put that line back into the macro (how it should appear)

What exactly should i enter into the "sheet code"

THANKS
 
Upvote 0
HalfAce,

I need it to be more generic as I ultimately want to select a cell, and run the macro. Having the cell address in the code limits it.

THANKS
 
Upvote 0
Code:
Sub Macro3() 
' 
' Keyboard Shortcut: Ctrl+k 
' 
ActiveCell = ActiveCell & "(XYZ)" 
With ActiveCell.Characters(Start:=1, Length:=19).Font 
.Name = "Arial" 
.FontStyle = "Regular" 
.Size = 12 
.Strikethrough = False 
.Superscript = False 
.Subscript = False 
.OutlineFont = False 
.Shadow = False 
.Underline = xlUnderlineStyleNone 
.ColorIndex = xlAutomatic 
End With 
With ActiveCell.Characters(Start:=20, Length:=5).Font 
.Name = "Arial" 
.FontStyle = "Bold" 
.Size = 12 
.Strikethrough = False 
.Superscript = False 
.Subscript = False 
.OutlineFont = False 
.Shadow = False 
.Underline = xlUnderlineStyleNone 
.ColorIndex = xlAutomatic 
End With 
Range("I471").Select 
End Sub
 
Upvote 0
jmiskey,

It works . . . partially.

The only issue now is that the (XYZ) is not bold

It seems that the following line places the text at that location bold

With ActiveCell.Characters(Start:=20, Length:=5).Font

Is there a way to make it just be the (XYZ) that is bold.

ALSO, the macro reverts back to this line when done.

End With
Range("I471").Select


How can I get it to end where it started

THANKS again
 
Upvote 0
jmiskey,

It works . . . partially.

The only issue now is that the (XYZ) is not bold

It seems that the following line places the text at that location bold

With ActiveCell.Characters(Start:=20, Length:=5).Font

Is there a way to make it just be the (XYZ) that is bold.

ALSO, the macro reverts back to this line when done.

End With
Range("I471").Select


How can I get it to end where it started

THANKS again
 
Upvote 0
jmiskey,

It works . . . partially.

The only issue now is that the (XYZ) is not bold

It seems that the following line places the text at that location bold

With ActiveCell.Characters(Start:=20, Length:=5).Font

Is there a way to make it just be the (XYZ) that is bold.

ALSO, the macro reverts back to this line when done.

End With
Range("I471").Select


How can I get it to end where it started

THANKS again
 
Upvote 0
jmiskey,

It works . . . partially.

The only issue now is that the (XYZ) is not bold

It seems that the following line places the text at that location bold

With ActiveCell.Characters(Start:=20, Length:=5).Font

Is there a way to make it just be the (XYZ) that is bold.

ALSO, the macro reverts back to this line when done.

End With
Range("I471").Select


How can I get it to end where it started

THANKS again
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,947
Members
448,534
Latest member
benefuexx

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