Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
jon jon is offline
external usenet poster
 
Posts: 6
Default complex cell formatting using VBA

I can manually format a cell (from within Excel) so that some of the words
in the cell are bold and others are not.

I want to be able to do this programmatically, from VBA, but cannot locate
any Help or sample code to do this. Can anyone provide some VBA code that
will format the first word in a cell as bold while leaving the remainder
not?

Thanks!

Jon

jbondy at sover dot net


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default complex cell formatting using VBA

Hi
to give you an idea:
sub foo()
dim i as integer
dim rng as range
set rng = selection
i = application.WorksheetFunction.Find(" ",rng)
rng.Characters(1, i-1).Font.Bold = True
end sub

will format the first word of cell A1 as bold


--
Regards
Frank Kabel
Frankfurt, Germany

jon wrote:
I can manually format a cell (from within Excel) so that some of the
words in the cell are bold and others are not.

I want to be able to do this programmatically, from VBA, but cannot
locate any Help or sample code to do this. Can anyone provide some
VBA code that will format the first word in a cell as bold while
leaving the remainder not?

Thanks!

Jon

jbondy at sover dot net

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default complex cell formatting using VBA

Just to add to Frank's code.

Tom Ogilvy's(I think) code will do Column A contiguous cells. Also turns the
first word to Upper Case JFTHOI.

Sub BoldFirstWord()
Dim rng As Range, cell As Range
Dim iloc As Long
Set rng = Range(Cells(1, 1), _
Cells(1, 1).End(xlDown))
rng.Font.Bold = False
For Each cell In rng
iloc = InStr(cell.Formula, " ")
If iloc = 0 Then
If Len(Trim(cell.Formula)) 1 Then
cell.Font.Bold = True
cell.Formula = UCase(cell.Formula)
End If
Else
cell.Formula = UCase(Left(cell.Formula, iloc - 1)) & _
Right(cell.Formula, Len(cell.Formula) - iloc + 1)
cell.Characters(Start:=1, length:=iloc - 1). _
Font.FontStyle = "Bold"
End If
Next
End Sub

Gord Dibben Excel MVP

On Tue, 17 Feb 2004 23:20:39 +0100, "Frank Kabel"
wrote:

Hi
to give you an idea:
sub foo()
dim i as integer
dim rng as range
set rng = selection
i = application.WorksheetFunction.Find(" ",rng)
rng.Characters(1, i-1).Font.Bold = True
end sub

will format the first word of cell A1 as bold


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
Complex conditional formatting [email protected] Excel Worksheet Functions 3 March 1st 07 05:44 PM
Complex cond. formatting...Pls. Help! Roz Excel Discussion (Misc queries) 1 December 20th 05 07:52 PM
Formula help for complex formatting. SCrowley Excel Worksheet Functions 6 October 29th 05 03:06 AM
complex?? Q about Conditional formatting AngelaG Excel Worksheet Functions 0 August 18th 05 08:16 PM
Complex Conditional Formatting Rob Excel Programming 2 December 5th 03 06:22 PM


All times are GMT +1. The time now is 03:17 AM.

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

About Us

"It's about Microsoft Excel"