Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Format Cell Colour/Font with VBA

Hi,

I'm a bit of a beginner and I'm trying to write a macro to format a
cell that will change the colour and place in italics only a set
selection of the cell.

I want to select the section of the cell that occurs after two "//"
characters, and change the colour and put in italics the following
characters of the cell.

(So: "This is an example // this is the bit that needs to be formatted"
would be formatted to show the "This is an example" section as normal
text, and the "// this is the bit that needs to be formatted" would be
red italics.)

The problem is that the "//" doesn't occur at any set point in the cell
(ie, may be the 5th character or the 10th character etc) and I can't
seem to work out a way to change only that selection without actually
knowing in advance where it may occur...

This would then loop through the entire worksheet and stop when all
occurances have been reformatted.

I've searched extensively for something similar to start from but no
luck, any help would be muchly appreciated!

Thanks
Ren

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Format Cell Colour/Font with VBA

If the cells contain text i.e not the results of formulae then you could
try:

Sub Frmt()
Dim theText As String
Dim cell As Range
For Each cell In Sheets("Sheet1").UsedRange.SpecialCells _
(xlCellTypeConstants)
theText = cell.Text
If InStr(1, theText, "//") 0 Then
With cell.Characters(InStr(1, theText, "//"), 255)
.Font.Italic = True
.Font.ColorIndex = 3
End With
End If
Next cell
End Sub

Hope this helps
Rowan

Ren wrote:
Hi,

I'm a bit of a beginner and I'm trying to write a macro to format a
cell that will change the colour and place in italics only a set
selection of the cell.

I want to select the section of the cell that occurs after two "//"
characters, and change the colour and put in italics the following
characters of the cell.

(So: "This is an example // this is the bit that needs to be formatted"
would be formatted to show the "This is an example" section as normal
text, and the "// this is the bit that needs to be formatted" would be
red italics.)

The problem is that the "//" doesn't occur at any set point in the cell
(ie, may be the 5th character or the 10th character etc) and I can't
seem to work out a way to change only that selection without actually
knowing in advance where it may occur...

This would then loop through the entire worksheet and stop when all
occurances have been reformatted.

I've searched extensively for something similar to start from but no
luck, any help would be muchly appreciated!

Thanks
Ren

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Format Cell Colour/Font with VBA

Perfect!! Thanks Rowan - this was driving me bonkers trying to work it
out ;)
(It's probably easy too).... I'll learn!

Ren

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Format Cell Colour/Font with VBA

You're welcome.

Ren wrote:
Perfect!! Thanks Rowan - this was driving me bonkers trying to work it
out ;)
(It's probably easy too).... I'll learn!

Ren

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
textBox font colour the same as cell font colour???????? Sophie Excel Discussion (Misc queries) 4 February 13th 09 10:15 AM
Changing font colour depending on cell value RunRonnyRun Excel Worksheet Functions 1 October 27th 08 08:28 PM
Conditional format Font Type(not colour) change frankod Excel Discussion (Misc queries) 2 June 24th 08 03:37 AM
Conditional format if cell=0 then font colour same as background . Paligap Excel Discussion (Misc queries) 2 December 20th 04 12:07 AM
changing font colour of row when cell contains date jason Excel Programming 3 May 8th 04 11:24 PM


All times are GMT +1. The time now is 07:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"