![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: Mar 2004
Posts: 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 |
|
|
|
|
|
#2 |
|
MrExcel MVP
Moderator Join Date: Aug 2002
Posts: 14,114
|
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. |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Apr 2003
Location: Alaska
Posts: 7,332
|
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 |
|
|
|
|
|
#4 |
|
Join Date: Mar 2004
Posts: 17
|
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 |
|
|
|
|
|
#5 |
|
Join Date: Mar 2004
Posts: 17
|
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 |
|
|
|
|
|
#6 |
|
MrExcel MVP
Moderator Join Date: Aug 2002
Posts: 14,114
|
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. |
|
|
|
|
|
#7 |
|
Join Date: Mar 2004
Posts: 17
|
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 |
|
|
|
|
|
#8 |
|
Join Date: Mar 2004
Posts: 17
|
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 |
|
|
|
|
|
#9 |
|
Join Date: Mar 2004
Posts: 17
|
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 |
|
|
|
|
|
#10 |
|
Join Date: Mar 2004
Posts: 17
|
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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|