Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2005, 02:06 AM
Authorized User
 
Join Date: Sep 2004
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

 
Old April 5th, 2005, 12:05 PM
Friend of Wrox
 
Join Date: Nov 2004
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.)
 
Old April 6th, 2005, 02:25 AM
Authorized User
 
Join Date: Sep 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I see. Thank you very much.

 
Old April 6th, 2005, 11:37 AM
Registered User
 
Join Date: Mar 2005
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


 
Old April 6th, 2005, 11:44 AM
Registered User
 
Join Date: Mar 2005
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

 
Old April 6th, 2005, 01:29 PM
Friend of Wrox
 
Join Date: Nov 2004
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.





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





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