Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro Question ?? | Excel Worksheet Functions | |||
question on macro | Excel Discussion (Misc queries) | |||
Macro Question | New Users to Excel | |||
MACRO QUESTION | Excel Worksheet Functions | |||
Question about macro | Excel Discussion (Misc queries) |