Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Text

Status
Not open for further replies.

gauca001

Programmer
May 12, 2012
2
I am building a macro (below) which changes the text "This is Brown colour" to "Brown" in col D. This works perfect. now in Col G (same row) I need to add "A" if the result in D is "Brown" and "B" if the result in D is "Red". Please help.

Sub Adv_Cert()
'
' Adv_Cert Macro
'
Columns("D:D").Select
Range("D2").Select
ActiveCell.FormulaR1C1 = _
"This is Brown colour"
Cells.Replace What:= _
"This is Brown colour", Replacement:= _
"Brown", LookAt:=xlPart, SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Columns("D:D").Select
Range("D2").Select
ActiveCell.FormulaR1C1 = _
"This is Red colour"
Cells.Replace What:= _
"This is Red colour", Replacement:= _
"Red", LookAt:=xlPart, SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False


End Sub
 
How about:

Code:
Range("D2").Value = "This is Brown colour"

Cells.Replace What:= _
"This is Brown colour", Replacement:= _
"Brown", LookAt:=xlPart, SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
[blue]
Select Case Range("D2").Value
    Case "Brown"
        Range("G2").Value = "A"
    Case "Red"
        Range("G2").Value = "B"
End Select[/blue]

Have fun.

---- Andy
 
hi,

Something like this???
Code:
    Dim r As Range
    
    With ActiveSheet
        For Each r In Range(.Cells(2, "D"), .Cells(.UsedRange.Rows.Count + .UsedRange.Row - 1, "D"))
            Select Case r.Value
                Case "Red"
                    .Cells(r.Row, "G").Value = "A"
                Case "Brown"
                    .Cells(r.Row, "G").Value = "B"
            End Select
        Next
    End With


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top