Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Macro for bolding and italicizing word strings

I want to bold and italicize every word that comes directly before or after
"v."

For example, my sheet is full of cases cited as "Smith v. Jones" etc. I
want everything on each side of "v." to be bolded and italicized, including
the "v."
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Macro for bolding and italicizing word strings

...."including the v."? So you want the whole cell bold/italics?
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Macro for bolding and italicizing word strings

Hi,

I hope it's a typo and you don't want the v in italics because I just read
your post again before replying and the first part contradicts the last.
having written the code I'll post it anyway. Alt +F11 to open VB editor,
right click 'This workbook' and insert module and paste this in and run it

Sub Prime_Lending()
For Each c In ActiveSheet.UsedRange
If WorksheetFunction.IsText(c) Then
Findv = InStr(UCase(c.Value), "V")
If Findv <= 1 Then GoTo getmeout
If Mid(c.Value, Findv - 1, 1) < " " And Mid(c.Value, _
Findv + 1, 1) < " " Then GoTo getmeout
With c.Characters(Start:=1, Length:=Len(c.Value)).Font
.FontStyle = "Bold Italic"
End With
With c.Characters(Start:=Findv, Length:=1).Font
.FontStyle = "Regular"
End With
End If
getmeout:
Next
End Sub

Mike
"suestew" wrote:

I want to bold and italicize every word that comes directly before or after
"v."

For example, my sheet is full of cases cited as "Smith v. Jones" etc. I
want everything on each side of "v." to be bolded and italicized, including
the "v."

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Macro for bolding and italicizing word strings

I ran your macro and it bolded and italicized all the words in the same cell
as a "v". I don't think you accounted for the period after the v. in "v."

How do I undo a macro?

"Mike H" wrote:

Hi,

I hope it's a typo and you don't want the v in italics because I just read
your post again before replying and the first part contradicts the last.
having written the code I'll post it anyway. Alt +F11 to open VB editor,
right click 'This workbook' and insert module and paste this in and run it

Sub Prime_Lending()
For Each c In ActiveSheet.UsedRange
If WorksheetFunction.IsText(c) Then
Findv = InStr(UCase(c.Value), "V")
If Findv <= 1 Then GoTo getmeout
If Mid(c.Value, Findv - 1, 1) < " " And Mid(c.Value, _
Findv + 1, 1) < " " Then GoTo getmeout
With c.Characters(Start:=1, Length:=Len(c.Value)).Font
.FontStyle = "Bold Italic"
End With
With c.Characters(Start:=Findv, Length:=1).Font
.FontStyle = "Regular"
End With
End If
getmeout:
Next
End Sub

Mike
"suestew" wrote:

I want to bold and italicize every word that comes directly before or after
"v."

For example, my sheet is full of cases cited as "Smith v. Jones" etc. I
want everything on each side of "v." to be bolded and italicized, including
the "v."

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Macro for bolding and italicizing word strings

On Sat, 6 Dec 2008 11:25:00 -0800, suestew
wrote:

I want to bold and italicize every word that comes directly before or after
"v."

For example, my sheet is full of cases cited as "Smith v. Jones" etc. I
want everything on each side of "v." to be bolded and italicized, including
the "v."


Your description is a bit confusing.

If the case description occupies the entire cell, you could use conditional
formatting.

--ron


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Macro for bolding and italicizing word strings

Hi,

What it does is look for a V that isn't the first letter in a cell. It then
checks there is a space both before and after the v and then bolds/italicises
the parts before and after the v. the font for the v is left as normal.

Your correct I didn't account for the period I missed that but all that
means is the period will be bold and the code revision below cures that. If
it isn't doing that for you then I'm confused. Post some sample data.

Sub Prime_Lending()
For Each c In ActiveSheet.UsedRange
If WorksheetFunction.IsText(c) Then
Findv = InStr(UCase(c.Value), "V")
If Findv <= 1 Then GoTo getmeout
If Mid(c.Value, Findv - 1, 1) < " " Or Mid(c.Value, _
Findv + 1, 1) < " " And Mid(c.Value, Findv + 1, 1) < _
"." Then GoTo getmeout
With c.Characters(Start:=1, Length:=Len(c.Value)).Font
.FontStyle = "Bold Italic"
End With
With c.Characters(Start:=Findv, Length:=2).Font
.FontStyle = "Regular"
End With
End If
getmeout:
Next
End Sub

Mike

"suestew" wrote:

I ran your macro and it bolded and italicized all the words in the same cell
as a "v". I don't think you accounted for the period after the v. in "v."

How do I undo a macro?

"Mike H" wrote:

Hi,

I hope it's a typo and you don't want the v in italics because I just read
your post again before replying and the first part contradicts the last.
having written the code I'll post it anyway. Alt +F11 to open VB editor,
right click 'This workbook' and insert module and paste this in and run it

Sub Prime_Lending()
For Each c In ActiveSheet.UsedRange
If WorksheetFunction.IsText(c) Then
Findv = InStr(UCase(c.Value), "V")
If Findv <= 1 Then GoTo getmeout
If Mid(c.Value, Findv - 1, 1) < " " And Mid(c.Value, _
Findv + 1, 1) < " " Then GoTo getmeout
With c.Characters(Start:=1, Length:=Len(c.Value)).Font
.FontStyle = "Bold Italic"
End With
With c.Characters(Start:=Findv, Length:=1).Font
.FontStyle = "Regular"
End With
End If
getmeout:
Next
End Sub

Mike
"suestew" wrote:

I want to bold and italicize every word that comes directly before or after
"v."

For example, my sheet is full of cases cited as "Smith v. Jones" etc. I
want everything on each side of "v." to be bolded and italicized, including
the "v."

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
find and replace numeric strings in larger text strings Mr Molio Excel Worksheet Functions 8 November 9th 11 05:17 PM
Code for counting number of word strings? Maria Excel Discussion (Misc queries) 3 June 19th 09 04:11 PM
Italicizing part of a cell Brian Bonner Excel Worksheet Functions 2 February 13th 06 09:57 PM
Italicizing in Excel acacia Charts and Charting in Excel 2 November 29th 05 10:17 PM
Macro Help - Bolding info ALC[_2_] Excel Programming 2 August 9th 05 02:51 PM


All times are GMT +1. The time now is 05:09 PM.

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"