MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 30th, 2004, 08:43 PM   #1
JamesPTuttle
 
Join Date: Mar 2004
Posts: 17
Default Insert text (add to) existing text in a cell

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
JamesPTuttle is offline   Reply With Quote
Old Mar 30th, 2004, 08:50 PM   #2
Joe4
MrExcel MVP
Moderator
 
Joe4's Avatar
 
Join Date: Aug 2002
Posts: 14,220
Default Re: Insert text (add to) existing text in a cell

Will the line
ActiveCell=ActiveCell & "XYZ"
do what you want?
__________________
TIPS FOR FINDING EXCEL SOLUTIONS
1. Use the built-in Help that comes with Excel/Access
2. Use the Search functionality on this board
3. A lot of VBA code can be acquired by using the Macro Recorder.
Joe4 is offline   Reply With Quote
Old Mar 30th, 2004, 08:52 PM   #3
HalfAce
MrExcel MVP
 
Join Date: Apr 2003
Location: Alaska
Posts: 7,332
Default Re: Insert text (add to) existing text in a cell

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?
__________________
XP & '03
Vista & '07
HalfAce is offline   Reply With Quote
Old Mar 30th, 2004, 09:26 PM   #4
JamesPTuttle
 
Join Date: Mar 2004
Posts: 17
Default Re: Insert text (add to) existing text in a cell

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
JamesPTuttle is offline   Reply With Quote
Old Mar 30th, 2004, 09:29 PM   #5
JamesPTuttle
 
Join Date: Mar 2004
Posts: 17
Default Re: Insert text (add to) existing text in a cell

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
JamesPTuttle is offline   Reply With Quote
Old Mar 30th, 2004, 09:33 PM   #6
Joe4
MrExcel MVP
Moderator
 
Joe4's Avatar
 
Join Date: Aug 2002
Posts: 14,220
Default Re: Insert text (add to) existing text in a cell

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
__________________
TIPS FOR FINDING EXCEL SOLUTIONS
1. Use the built-in Help that comes with Excel/Access
2. Use the Search functionality on this board
3. A lot of VBA code can be acquired by using the Macro Recorder.
Joe4 is offline   Reply With Quote
Old Mar 30th, 2004, 09:48 PM   #7
JamesPTuttle
 
Join Date: Mar 2004
Posts: 17
Default Re: Insert text (add to) existing text in a cell

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
JamesPTuttle is offline   Reply With Quote
Old Mar 30th, 2004, 09:51 PM   #8
JamesPTuttle
 
Join Date: Mar 2004
Posts: 17
Default Re: Insert text (add to) existing text in a cell

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
JamesPTuttle is offline   Reply With Quote
Old Mar 30th, 2004, 10:03 PM   #9
JamesPTuttle
 
Join Date: Mar 2004
Posts: 17
Default Re: Insert text (add to) existing text in a cell

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
JamesPTuttle is offline   Reply With Quote
Old Mar 30th, 2004, 10:03 PM   #10
JamesPTuttle
 
Join Date: Mar 2004
Posts: 17
Default Re: Insert text (add to) existing text in a cell

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
JamesPTuttle is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 05:21 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.