Question

Bold/Italic only the variable name within a cell's value

Asked by: slindeen

Using Excel XP, I have a cell formula that references another's cell's value within it.  

Here is the cell's formula;
 ="It is our company’s objective that "&Course_Name&"'s fleet will receive professional, timely and systematic service."

I have named that other cell "Course_Name".  What I want to do is have only that Course_Name value to be printed as bold italics. I can do that if I hard code the name of the course in it by highlighting it and clicking the appropriate format buttons.  But as soon as I make the cell a formula (=) and pull the information from the named field, my formatting buttons are greyed out.


I want the printed results to look like this assuming Course_Name = "ABC Course" with ABC Course's printed as bold and italicized everything else in normal print;
It is our company's objective that ABC Course's fleet will receive professional, timely and systematic service.



This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-08-26 at 08:16:48ID20720401
Tags

excel

,

cell

,

bold

,

italic

,

value

Topic

Microsoft Excel Spreadsheet Software

Participating Experts
3
Points
500
Comments
17

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. bold and italics
    hi i heard that we can make letters bold italic or condenced while printing from dos with the help of ascii charactors by sending correct ascii charactors at the beginning of the line. please help me in this regards sincerely rajesh
  2. Italic text in Msflexgrid
    How do I change text to Italic in a fixed cell in Msflexgrid? Thanks.
  3. Check to see if text is in italics.
    How do I check to see if font is in italics? If I have a name in several places on my sheet, I want to only count the ones that are in italics. Thanks.... urgent.
  4. VB Excel - How to make some of the text in a comment ap…
    I've managed to get my VB code to add a comment to a cell on an Excel worksheet by using the .Comment properties of the cell I can add a string of text using the .Comment.Text Text:= "This is line 1" & Chr(10) & "This is line 2" How do I make t...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: bruintjePosted on 2003-08-26 at 08:29:21ID: 9224825

Neither built-in worksheet functions nor UDFs can change formatting. In order to do what you want, you'd need an Event Macro.

something like

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
        With Target
            If .Count > 1 Then Exit Sub
            If .Column <= 2 Then
                With Cells(.Row, 3)
                    .Value = Cells(.Row, 1).Text & vbNewLine & _
                            Cells(.Row, 2).Text
                    .Characters(1, Len(Cells(.Row, 1).Text)). _
                            Font.Bold = True
                    With .Characters(Len(Cells(.Row, 1).Text) + 2).Font
                        .Bold = False
                        .Italic = True
                    End With
                End With
            End If
        End With
    End Sub

Put this in the worksheet code module (right-click on the worksheet tab, choose View Code, paste the code in the window that  opens, then click the XL icon on the toolbar to return to XL)

If you only want this macro to affect a certain range, replace

    If .Column <= 2 Then

with something like

    If Not Intersect(.Cells, Range("A10:B20")) Is Nothing Then

source : http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=271120022335543994%25jemcgimpsey%40mvps.org

and the author is correct sorry to make it so hard but what you want to do is hard ......... if you need more help on getting this running as per requirement just comment

 

by: PaultheGreatPosted on 2003-08-26 at 08:39:16ID: 9224893

check out http:Q_20489190.html... (example for you shown below):


leave your cell with this:
="It is our company’s objective that " & Course_Name & "'s fleet will receive professional, timely and systematic service."

but then put this code in the code module for whichever worksheet this applies to (press Alt+F11, double-click on the worksheet in the window on the left):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Dim searchForThis As String: searchForThis = "Course_Name"
    If InStr(1, Target.Formula, searchForThis) = 0 Then Exit Sub
    Target.Characters(InStr(1, Target.Formula, searchForThis), Len(searchForThis)).Font.Bold = True
End Sub

hope that helps!
-PtG

 

by: PaultheGreatPosted on 2003-08-26 at 08:41:21ID: 9224908

wow, it took me at least 10 mins to do that? shoot... i gotta work on that!

Regards,
PtG

 

by: slindeenPosted on 2003-08-28 at 09:43:13ID: 9242021

OK - I can't seem to get either of these solutions to work.  I've been playing with PtG's mostly because I "think" I understand that one better.

Here are some other caveats that I should perhaps mention;
1. The named field "Course_Name" is not on this same sheet but on another sheet within the same workbook.
2. The reference to "&Course_Name&" appears multiple times on this page where I want the bold/italicized text to appear
3. Not only does the reference to "&Course_Name&" appear in multiple cells, it can appear multiple times in any cell.

I have the following code in the worksheets "Change" section.  Is that correct?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)    
    Dim searchForThis As String: searchForThis = "Course_Name"
    If InStr(1, Target.Formula, searchForThis) = 0 Then Exit Sub
    Target.Characters(InStr(1, Target.Formula, searchForThis), Len(searchForThis)).Font.Bold = True
    Target.Characters(InStr(1, Target.Formula, searchForThis), Len(searchForThis)).Font.Italic = True

End Sub

 

by: PaultheGreatPosted on 2003-08-28 at 09:54:22ID: 9242100

try this:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)    
    Dim searchForThis As String: searchForThis = Range(Names("Course_Name").Value)
    t1 = 0
    While InStr(t1 + 1, Target.Formula, searchForThis) > 0
        t1 = InStr(t1 + 1, Target.Formula, searchForThis)
        Target.Characters(InStr(1, Target.Formula, searchForThis), Len(searchForThis)).Font.Bold = True
        Target.Characters(InStr(1, Target.Formula, searchForThis), Len(searchForThis)).Font.Italic = True
    Wend
End Sub

hope that helps!
-PtG

P.S. - yes, put it in the Worksheet_Change event in the module whichever worksheet you want it to trigger on a change in... did that make sense? :-P

 

by: slindeenPosted on 2003-08-28 at 11:19:32ID: 9242709

Sorry I can't seem go that to work either.  :-(  I found out that it did not like the reference to Course_Name when setting the searchForThis value.  Perhaps because its from another sheet?  To get by it, I set J2 cells value on this worksheet to = Course_Name from the other work sheet. That allowed me to at least run the macro without bombing out.  

So here's how it looks now in the change event of Sheet12;

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

   'Dim searchForThis As String: searchForThis = Range(Names("Course_Name").Value)
    Dim searchForThis As String: searchForThis = Range("J2").Value
    t1 = 0
    While InStr(t1 + 1, Target.Formula, searchForThis) > 0
         t1 = InStr(t1 + 1, Target.Formula, searchForThis)
        Target.Characters(InStr(1, Target.Formula, searchForThis), Len(searchForThis)).Font.Bold = True
        Target.Characters(InStr(1, Target.Formula, searchForThis), Len(searchForThis)).Font.Italic = True
    Wend

End Sub

Any suggestions?

 

by: PaultheGreatPosted on 2003-08-28 at 11:29:16ID: 9242763

I figured out what it was... I forgot to put in "Application.", so it was referring simply to the ranges/named ranges on that worksheet... here you go, enjoy!

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Dim searchForThis As String: searchForThis = Application.Range(Application.Names("Course_Name").Value)
    t1 = 0
    While InStr(t1 + 1, Target.Formula, searchForThis) > 0
        t1 = InStr(t1 + 1, Target.Formula, searchForThis)
        Target.Characters(InStr(1, Target.Formula, searchForThis), Len(searchForThis)).Font.Bold = True
        Target.Characters(InStr(1, Target.Formula, searchForThis), Len(searchForThis)).Font.Italic = True
    Wend
End Sub

Regards,
PtG

 

by: slindeenPosted on 2003-08-29 at 09:00:10ID: 9249023

This is not working either for several reasons.  
1. Target.Formula.  This is targeting the cell that the change is made in, what I need it to do is reference other cell(s).  (Will deal with that issue later)
2. Searching for searchForThis in Target.Formula doesn't work.  You either have to search for "&Course_Name&" or searchForthis in Target.Text
3. t1 creates an endless loop. I added the t2 test
4. It still does not bold or italicize the needed text.  The Target.Characters statements "look" ok to me - but obviously something is wrong since it is not achieving the desired results

Anyways I thought if I could at least get one targetted cell to work for just one occurance, then I could make changes for other cells and multiple occurances.  But I'm not having any luck.  This is where I am at now.  

Dim searchForThis As String: searchForThis = Application.Range(Application.Names("Course_Name").Value)
    t1 = 0
    t2 = 0
    'While InStr(t1 + 1, Target.Formula, searchForThis) > 0 ; Commented out and replaced with next line
     While InStr(t2 + 1, Target.Formula, "&Course_Name&") > 0
        't1 = InStr(t1 + 1, Target.Formula, searchForThis) ; Commented out and replaced with next line
        t1 = InStr(t2 + 1, Target.Text, searchForThis)
        Target.Characters(InStr(Target.Text, searchForThis), Len(searchForThis)).Font.Bold = True
        Target.Characters(InStr(1, Target.Text, searchForThis), Len(searchForThis)).Font.Italic = True
        t2 = t2 + Len(searchForThis)
    Wend

The theory is; I have a "Configuration Sheet" with data on it.  One of which is Course_Name.  I have another sheet called Special_Options.  Anytime Course_Name gets changed on the one sheet, I would like all text occurances on the Special_Options page to be bold and highlighted.  

I'm still open to suggestions

 

by: PaultheGreatPosted on 2003-08-29 at 09:49:59ID: 9249364

I've tried a couple things with this... and I found out that you can only change bold and italic for specific characters in a cell that ***doesn't have a formula.*** This is rather unfortunate, since that's kinda the whole point for you. However, I do have a suggestion:

If you have a string variable that stores the current value of Course_Name, then when Course_Name is changed you can search through and replace all occurrances of the previous value of Course_Name with the new value, applying bold/italic at the same time. In order for this to work, you'll have to change all instances of "&Course_Name&" with the actual value for Course_Name, and remove the equals sign (so basically make it regular text).

Note: there still *might* be a possibility of searching through the formula and being able to bold/italicize the text... don't count on it. I'll try to figure something out this weekend, but I'm really busy today, I have a lot to do at work, so I can't post more than one or two more posts today (maybe tonight I can).

Code for my suggestion:
==================

'place the following code in the ThisWorkbook module:

Dim myCurrentCourseName As String

Private Sub Workbook_Open()
    myCurrentCourseName = Application.Range(Application.Names("Course_Name").Value)
End Sub

'place the following code in the "Configuration Sheet" module:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Target.Address <> Application.Names("Course_Name").RefersToRange.Address Then Exit Sub
    Dim searchForThis As String: searchForThis = ThisWorkbook.myCurrentCourseName
    Dim replaceWithThis As String: replaceWithThis = Application.Range(Application.Names("Course_Name").Value)
    Dim c1 As Range
    For Each c1 In ThisWorkbook.Worksheets("Special_Options").UsedRange.Cells
        t1 = 0
        While InStr(t1 + 1, c1, searchForThis) > 0
            t1 = InStr(t1 + 1, c1, searchForThis)
            c1 = Left(c1.Text, t1 - 1) & replaceWithThis & Mid(c1.Text, t1 + Len(searchForThis))
            c1.Characters(InStr(1, c1, replaceWithThis), Len(replaceWithThis)).Font.Bold = True
            c1.Characters(InStr(1, c1, replaceWithThis), Len(replaceWithThis)).Font.Italic = True
        Wend
    Next
    ThisWorkbook.myCurrentCourseName = replaceWithThis
End Sub

=============
after you put the code into your workbook and make the necessary changes, you will have to save and reload the workbook (so it activates the Workbook_Open event) and then everything should work fine (works just fine for me).

hope that helps!
-PtG

 

by: slindeenPosted on 2003-08-29 at 12:39:35ID: 9250722

You are going to hate me and be sorry that you ever answered this post (LOL)
BUT---We ARE getting closer!  
I had to change the "Dim myCurrentCourseName As String" to "Public myCurrentCourseName As String"
I realize this will apply to all open workbooks, but thats the only way I got it to work.

Then the code seems to work on the FIRST occurance of the course name within a cell.  It does replace all occurances of the course name, but it does not bold/italic them all, just the first one within a given cell.  It does work on all cells on the sheet.  So now we have to tackle the problem that within a given cell, course name may be referenced more than once - and make them all bold/italic.

Then I have a  concern of what happens if the user changes the course name to a blank field.    Actually I know, its not a problem when they blank the field, big problem when they re-enter a value.  Is there a way to prevent the course name value from ever being a null but can still have any value?  I've tried the validation and using text length, but it still allows me to blank the cell (even though I left the Ingore Blank unchecked)

No rush on this Paul - what you've done so far has been super!  I REALLY do appreciate the input!

 

by: slindeenPosted on 2003-08-29 at 12:55:09ID: 9250865

Never mind on then preventing blank Course Name.
I added the following line before the Dim stmts in Configuration Sheet module.
   If Target.Value = "" Then Exit Sub

Guess that lunch break helped....

 

by: PaultheGreatPosted on 2003-08-29 at 13:00:48ID: 9250888

lol btw, you might want to try something like this:

If Len(Target.Value) < 2

just in case the user types in a space to clear it or something like that...

yes, my bad, I mean to make that Public... in fact, I made it Public in mine when I was testing it, but forgot to re-paste that code in there :-)

hey, I'm gonna be really busy the rest of the day, I'll try to post tomorrow. And don't worry about it, I enjoy doing this kinda stuff... just wish I had more time to do it!

Regards,
PtG

 

by: slindeenPosted on 2003-09-09 at 08:32:06ID: 9321296

Hi Paul,
Now that I've finished with my month end processes I can get back into designing - so continuing where we left off...

Believe it or not, I've actually caught people typing in spaces equal to the previous entry in order to clear it.  Amazing what people think of!  So I'm including this line as well;
If Left(Target.Value, 1) = " " Then Exit Sub

Any  more thought on how to replace multiple occurances in one cell?  I consider myself pretty good at this stuff, but I admit I'm a little lost in the for each with the while loops you've provided.  So Here's where I'm at.  Any thing else you can add is appreciated.
Thanks!
Sharon


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Target.Address <> Application.Names("Course_Name").RefersToRange.Address Then Exit Sub
    If Target.Value = "" Then Exit Sub
    If Len(Target.Value) < 2 Then Exit Sub
    If Left(Target.Value, 1) = " " Then Exit Sub
    Dim searchForThis As String: searchForThis = ThisWorkbook.myCurrentCourseName
    Dim replaceWithThis As String: replaceWithThis = Application.Range(Application.Names("Course_Name").Value)
    Dim c1 As Range
    Sheets("Special_Options").Unprotect
    For Each c1 In ThisWorkbook.Worksheets("Special_Options").UsedRange.Cells
        t1 = 0
        While InStr(t1 + 1, c1, searchForThis) > 0
            t1 = InStr(t1 + 1, c1, searchForThis)
            c1 = Left(c1.Text, t1 - 1) & replaceWithThis & Mid(c1.Text, t1 + Len(searchForThis))
            c1.Characters(InStr(1, c1, replaceWithThis), Len(replaceWithThis)).Font.Bold = True
            c1.Characters(InStr(1, c1, replaceWithThis), Len(replaceWithThis)).Font.Italic = True
        Wend
    Next
    Sheets("Special_Options").Protect
    ThisWorkbook.myCurrentCourseName = replaceWithThis
    Range("B4").Value = replaceWithThis
End Sub

 

by: PaultheGreatPosted on 2003-09-10 at 22:01:54ID: 9334400

here's one thing that i messed up:

c1.Characters(t1, Len(replaceWithThis)).Font.Bold = True
c1.Characters(t1, Len(replaceWithThis)).Font.Italic = True

use the two above lines instead of the ones you were using before... it still seems to be having issues, it only makes the last changed text bold/italic... i'll teake a look at it more if i get time, sorry i'm just moving into college, lotsa stuff going on :-)

Regards,
PtG

 

by: slindeenPosted on 2003-10-06 at 08:36:50ID: 9498798

Attn Moderato: This question has not been answered completely, but has been of benefit.  Can I award 300  partial points to PaultheGreat?

 

by: PaultheGreatPosted on 2003-10-06 at 11:36:08ID: 9500038

slindeen,
if you still haven't solved this problem and if you want i can try to make time at some point to take another look at it... i just always seem to be so busy here, my first term in college... i haven't made a real post for almost a month! so let me know...

Regards,
PtG

 

by: DreamboatPosted on 2003-12-20 at 15:06:36ID: 9979654

No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: PaultheGreat {http:#9500038}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Dreamboat
EE Page Editor - MS Office Technology Channel

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...