#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Macro Question

I run the following macro commands and they work fine. It simply looks at the
cell and if it matches the text in this case B.S. it replaces it with B.S.
with the cell color coded in this case color 3. My question is that this
macro requires that the cell entry be B.S., how could I look at the cells
value as opposed to what's entered. I would prefer that the cell receive the
B.S. value by using a formula that picks up the B.S value. But the macro
below at this time simply sees the formula and not the value.

Any help would be greatly appreciated!

Range("M7:CK100").Select
Application.ReplaceFormat.Interior.ColorIndex = 3
Selection.Replace What:="B.S.", Replacement:="B.S.", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=True
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Macro Question

Sub McCloud()
Set r = Range("M7:CK100")
For Each rr In r
With rr
If .Value = "B.S." Then
.Interior.ColorIndex = 3
End If
End With
Next
End Sub

--
Gary''s Student - gsnu200744


"McCloudK" wrote:

I run the following macro commands and they work fine. It simply looks at the
cell and if it matches the text in this case B.S. it replaces it with B.S.
with the cell color coded in this case color 3. My question is that this
macro requires that the cell entry be B.S., how could I look at the cells
value as opposed to what's entered. I would prefer that the cell receive the
B.S. value by using a formula that picks up the B.S value. But the macro
below at this time simply sees the formula and not the value.

Any help would be greatly appreciated!

Range("M7:CK100").Select
Application.ReplaceFormat.Interior.ColorIndex = 3
Selection.Replace What:="B.S.", Replacement:="B.S.", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=True

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro Question

If you're not using Format|Conditional formatting, you may want to use that
instead of a macro:

If you select the range first (M7:ck100)
then with M7 the activecell
format|Conditional formatting
formula is:
=countif(m7,"*b.s.*")0

And give it a pretty format.



McCloudK wrote:

I run the following macro commands and they work fine. It simply looks at the
cell and if it matches the text in this case B.S. it replaces it with B.S.
with the cell color coded in this case color 3. My question is that this
macro requires that the cell entry be B.S., how could I look at the cells
value as opposed to what's entered. I would prefer that the cell receive the
B.S. value by using a formula that picks up the B.S value. But the macro
below at this time simply sees the formula and not the value.

Any help would be greatly appreciated!

Range("M7:CK100").Select
Application.ReplaceFormat.Interior.ColorIndex = 3
Selection.Replace What:="B.S.", Replacement:="B.S.", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=True


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Macro Question

I must be using your suggestion wrong. Can you give me the exact command.

"Gary''s Student" wrote:

Sub McCloud()
Set r = Range("M7:CK100")
For Each rr In r
With rr
If .Value = "B.S." Then
.Interior.ColorIndex = 3
End If
End With
Next
End Sub

--
Gary''s Student - gsnu200744


"McCloudK" wrote:

I run the following macro commands and they work fine. It simply looks at the
cell and if it matches the text in this case B.S. it replaces it with B.S.
with the cell color coded in this case color 3. My question is that this
macro requires that the cell entry be B.S., how could I look at the cells
value as opposed to what's entered. I would prefer that the cell receive the
B.S. value by using a formula that picks up the B.S value. But the macro
below at this time simply sees the formula and not the value.

Any help would be greatly appreciated!

Range("M7:CK100").Select
Application.ReplaceFormat.Interior.ColorIndex = 3
Selection.Replace What:="B.S.", Replacement:="B.S.", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=True

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Macro Question

Conditional Formatting only allows 3 conditions.....I need over a dozen

"Dave Peterson" wrote:

If you're not using Format|Conditional formatting, you may want to use that
instead of a macro:

If you select the range first (M7:ck100)
then with M7 the activecell
format|Conditional formatting
formula is:
=countif(m7,"*b.s.*")0

And give it a pretty format.



McCloudK wrote:

I run the following macro commands and they work fine. It simply looks at the
cell and if it matches the text in this case B.S. it replaces it with B.S.
with the cell color coded in this case color 3. My question is that this
macro requires that the cell entry be B.S., how could I look at the cells
value as opposed to what's entered. I would prefer that the cell receive the
B.S. value by using a formula that picks up the B.S value. But the macro
below at this time simply sees the formula and not the value.

Any help would be greatly appreciated!

Range("M7:CK100").Select
Application.ReplaceFormat.Interior.ColorIndex = 3
Selection.Replace What:="B.S.", Replacement:="B.S.", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=True


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro Question

If I had seen that requirement in your original post, I wouldn't have suggested
conditional formatting in xl2003 and below.

BTW, xl2007 allows lots more rules.



McCloudK wrote:

Conditional Formatting only allows 3 conditions.....I need over a dozen

"Dave Peterson" wrote:

If you're not using Format|Conditional formatting, you may want to use that
instead of a macro:

If you select the range first (M7:ck100)
then with M7 the activecell
format|Conditional formatting
formula is:
=countif(m7,"*b.s.*")0

And give it a pretty format.



McCloudK wrote:

I run the following macro commands and they work fine. It simply looks at the
cell and if it matches the text in this case B.S. it replaces it with B.S.
with the cell color coded in this case color 3. My question is that this
macro requires that the cell entry be B.S., how could I look at the cells
value as opposed to what's entered. I would prefer that the cell receive the
B.S. value by using a formula that picks up the B.S value. But the macro
below at this time simply sees the formula and not the value.

Any help would be greatly appreciated!

Range("M7:CK100").Select
Application.ReplaceFormat.Interior.ColorIndex = 3
Selection.Replace What:="B.S.", Replacement:="B.S.", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=True


--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Macro Question

Could you help me with Gary's student reply. It looks like it should work but
I keep getting errors on it.

Thanks for all your time

"Dave Peterson" wrote:

If I had seen that requirement in your original post, I wouldn't have suggested
conditional formatting in xl2003 and below.

BTW, xl2007 allows lots more rules.



McCloudK wrote:

Conditional Formatting only allows 3 conditions.....I need over a dozen

"Dave Peterson" wrote:

If you're not using Format|Conditional formatting, you may want to use that
instead of a macro:

If you select the range first (M7:ck100)
then with M7 the activecell
format|Conditional formatting
formula is:
=countif(m7,"*b.s.*")0

And give it a pretty format.



McCloudK wrote:

I run the following macro commands and they work fine. It simply looks at the
cell and if it matches the text in this case B.S. it replaces it with B.S.
with the cell color coded in this case color 3. My question is that this
macro requires that the cell entry be B.S., how could I look at the cells
value as opposed to what's entered. I would prefer that the cell receive the
B.S. value by using a formula that picks up the B.S value. But the macro
below at this time simply sees the formula and not the value.

Any help would be greatly appreciated!

Range("M7:CK100").Select
Application.ReplaceFormat.Interior.ColorIndex = 3
Selection.Replace What:="B.S.", Replacement:="B.S.", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=True

--

Dave Peterson


--

Dave Peterson

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro Question

If you have 12 different rules, I'm not sure I'd want to loop through all the
cells in that range 12 different times.

Maybe you could use something like:

Option Explicit
Sub testme01()

Dim myRng As Range
Dim myCell As Range
Dim myWords As Variant
Dim myColors As Variant
Dim iCtr As Long
Dim FirstAddress As String
Dim FoundCell As Range

Set myRng = Worksheets("sheet1").Range("M7:CK100")
'remove any existing colors?????
myRng.Interior.ColorIndex = xlNone

myWords = Array("b.s.", "hi", "another")
myColors = Array(3, 5, 9)

If UBound(myWords) < UBound(myColors) Then
MsgBox "error--number of words and colors don't match!"
Exit Sub
End If

For iCtr = LBound(myWords) To UBound(myWords)
FirstAddress = ""
With myRng
Set FoundCell = .Cells.Find(what:=myWords(iCtr), _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlPart, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)

If FoundCell Is Nothing Then
'that word wasn't found. Do nothing
Else
FirstAddress = FoundCell.Address
Do
FoundCell.Interior.ColorIndex = myColors(iCtr)
Set FoundCell = .FindNext(after:=FoundCell)
If FoundCell.Address = FirstAddress Then
Exit Do
End If
Loop
End If
End With
Next iCtr

End Sub

You'll update the myWords array with your list of 12 words. And update the
myColors with the corresponding numbers.



McCloudK wrote:

Could you help me with Gary's student reply. It looks like it should work but
I keep getting errors on it.

Thanks for all your time

"Dave Peterson" wrote:

If I had seen that requirement in your original post, I wouldn't have suggested
conditional formatting in xl2003 and below.

BTW, xl2007 allows lots more rules.



McCloudK wrote:

Conditional Formatting only allows 3 conditions.....I need over a dozen

"Dave Peterson" wrote:

If you're not using Format|Conditional formatting, you may want to use that
instead of a macro:

If you select the range first (M7:ck100)
then with M7 the activecell
format|Conditional formatting
formula is:
=countif(m7,"*b.s.*")0

And give it a pretty format.



McCloudK wrote:

I run the following macro commands and they work fine. It simply looks at the
cell and if it matches the text in this case B.S. it replaces it with B.S.
with the cell color coded in this case color 3. My question is that this
macro requires that the cell entry be B.S., how could I look at the cells
value as opposed to what's entered. I would prefer that the cell receive the
B.S. value by using a formula that picks up the B.S value. But the macro
below at this time simply sees the formula and not the value.

Any help would be greatly appreciated!

Range("M7:CK100").Select
Application.ReplaceFormat.Interior.ColorIndex = 3
Selection.Replace What:="B.S.", Replacement:="B.S.", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=True

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
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
Macro Question ?? carl Excel Worksheet Functions 7 May 19th 07 12:45 AM
question on macro Harry Excel Discussion (Misc queries) 8 April 13th 06 05:25 PM
Macro Question Greg New Users to Excel 4 March 24th 06 04:47 PM
MACRO QUESTION Eddy Stan Excel Worksheet Functions 2 February 28th 06 02:08 PM
Question about macro Jason Excel Discussion (Misc queries) 0 April 27th 05 11:37 PM


All times are GMT +1. The time now is 04:32 AM.

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"