Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ela ela is offline
external usenet poster
 
Posts: 16
Default To color string of variable size

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default To color string of variable size

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default To color string of variable size

On Wed, 4 Aug 2010 17:33:23 +0800, "ela" wrote:

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


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
+++++++++++++++++++++++++++++
  #4   Report Post  
Posted to microsoft.public.excel.programming
ela ela is offline
external usenet poster
 
Posts: 16
Default To color string of variable size

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?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default To color string of variable size

On Thu, 5 Aug 2010 08:35:24 +0800, "ela" wrote:

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?


You will have to tell me when you run it against your data.
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
Trying To Append String Variable To Another String Variable Joe K. Excel Programming 3 October 6th 07 02:11 AM
Create Variable Length String Dependent Upon Size List ags5406 Excel Programming 1 May 28th 06 11:30 PM
How to find out the size of a variable-size array ? Adrian[_7_] Excel Programming 1 July 6th 04 09:12 AM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
How do I convert an integer variable to a string variable? dumbass Excel Programming 2 May 21st 04 07:34 PM


All times are GMT +1. The time now is 07:06 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"