Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 5th, 2005, 02:06 AM
Authorized User
 
Join Date: Sep 2004
Location: stuttgart, , Germany.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to highlight in Excel

Hi,

I want to highlight the search results of some words in Excel by using VB. Could anybody give some ideas or examples?

Thanks in advance.
Haiying

Reply With Quote
  #2 (permalink)  
Old April 5th, 2005, 12:05 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

You will only be able to apply formatting to the entire contents of a cell. (It sounds like you want to highlight some of the contents of a given cell, but not other parts of that same cell.)
Reply With Quote
  #3 (permalink)  
Old April 6th, 2005, 02:25 AM
Authorized User
 
Join Date: Sep 2004
Location: stuttgart, , Germany.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I see. Thank you very much.

Reply With Quote
  #4 (permalink)  
Old April 6th, 2005, 11:37 AM
Registered User
 
Join Date: Mar 2005
Location: Johannesburg, , South Africa.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually there is a crude way you can "highlight" specific contents of a cell by changing the font attributes. Let's say you have selected the cell in which the text you want to "highlight" resides and you know the text start offset (intStart) in the cell and its length (intlength) then the following code should change that text's font attributes to "highlight" it

  With ActiveCell.Characters(Start:=intStart, Length:=intLength).Font
    .FontStyle = "Bold Italic"
    .Size = 12
  End With

You will probably want to play around with the FontStyle and Size depending on the attributes of the original text in the cell. There may be better solutions than this, but I don't know of any.

Cheers
nic


Reply With Quote
  #5 (permalink)  
Old April 6th, 2005, 11:44 AM
Registered User
 
Join Date: Mar 2005
Location: Johannesburg, , South Africa.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just thought after I posted my response that you can also change the font colour and underline it by setting the .ColorIndex and .Underline properties in the same code. If this doesn't highlight your search results then I don't know what will.

Cheers again
nic

Reply With Quote
  #6 (permalink)  
Old April 6th, 2005, 01:29 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Wow! I was wrong. I didn’t think you could format sections of a cell.

But I tried it, and you can. Sorry to steer you wrong Haiying.
Kudos Nic.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to highlight changes SoberGuy Word VBA 2 October 24th, 2008 11:46 AM
Select or Highlight Text ~Bean~ General .NET 0 November 9th, 2005 12:31 PM
VBA Excel highlight all columns crmpicco Excel VBA 4 April 19th, 2005 02:15 AM
how to highlight in Powerpoint haiying Access VBA 6 April 6th, 2005 08:04 AM
Highlight record JpJoe Access 4 January 28th, 2005 09:58 AM



All times are GMT -4. The time now is 03:12 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.