PC Review


Reply
Thread Tools Rate Thread

To color string of variable size

 
 
ela
Guest
Posts: n/a
 
      4th Aug 2010
The following codes color a character in green. Is there any way to color a
string of variable size, e.g. "abc", "ha, ha, I got you" etc?

Sub GreenLetter()
Dim s As String * 1
Dim c As Range
Dim i As Long

s = InputBox("Which letter to greenden?")

If s Like "[!A-Za-z]" Then
MsgBox ("Must specify a LETTER")
Exit Sub
End If

For Each c In Selection
With c
If .HasFormula Then .Value = .Text
For i = 1 To Len(.Text)
If LCase(Mid(.Text, i, 1)) = LCase(s) Then
.Characters(i, 1).Font.Color = RGB(30, 255, 15)
'Selection.Interior.ColorIndex = [A1].Interior.ColorIndex
End If
Next i
End With
Next c
End Sub


 
Reply With Quote
 
 
 
 
Master Blaster
Guest
Posts: n/a
 
      4th Aug 2010
This should work:

Sub GreenLetter()
Dim s As String
Dim c As Range
Dim i As Long


s = InputBox("Which letter to greenden?")
LL = Len(s)

If s Like "[!A-Za-z]" Then
MsgBox ("Must specify a LETTER")
Exit Sub
End If


For Each c In Selection
With c
If .HasFormula Then .Value = .Text
For i = 1 To Len(.Text)
If LCase(Mid(.Text, i, LL)) = LCase(s) Then
.Characters(i, LL).Font.Color = RGB(30, 255, 15)
Selection.Interior.ColorIndex =
[A1].Interior.ColorIndex
End If
Next i
End With
Next c
End Sub
 
Reply With Quote
 
ela
Guest
Posts: n/a
 
      5th Aug 2010
> Modifying your code a bit:
>
> =====================
> Option Explicit
> Sub GreenPhrase()
> Dim s As String
> Dim c As Range
> Dim i As Long, j As Long
>
> s = InputBox("Which phrase to green?")
> j = Len(s)
>
> For Each c In Selection
> With c
> i = InStr(1, .Text, s)
> .Font.ColorIndex = xlAutomatic
> If i > 0 Then
> .Characters(i, j).Font.Color = RGB(30, 255, 15)
> 'Selection.Interior.ColorIndex =
> [A1].Interior.ColorIndex
> End If
> End With
>
> Next c
> End Sub
> +++++++++++++++++++++++++++++


Is this modification making the code running faster?


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Variable Length String Dependent Upon Size List ags5406 Microsoft Excel Programming 1 28th May 2006 11:30 PM
Probem: No size set for variable length data type: String, using OracleDataAdapter Benny Microsoft ADO .NET 4 21st Dec 2005 05:24 AM
"No size set for variable length data" Oracle update error with empty string in .NET arvee Microsoft ADO .NET 1 8th Apr 2005 12:46 PM
OracleCommadbuilder: Exception: Parameter 'p1': No size set for variable length data type: String. Peter Meinl Microsoft ADO .NET 6 17th Sep 2004 02:00 PM
No size set for variable length data type: String Javier Ros Microsoft ADO .NET 0 8th Jul 2003 09:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:19 PM.