+ Reply to Thread
Results 1 to 6 of 6

Find and replace with condition

  1. #1
    Stuart
    Guest

    Find and replace with condition

    Help - I want to update values in a column, but this is with conditions in
    other cells e.g.
    A B C
    1 blue Fred
    2 black Jim
    3 blue Steve

    change blue to red in column A, where content of B = Fred

    Can this be done?

  2. #2
    Bob Phillips
    Guest

    Re: Find and replace with condition


    For i = 1 To Cells(Rows.Count,"A").End(xlUp).Row
    If Cells(i,"A").Value = "blue" And Cells(i,"B").Value = "Fred") Then
    Cells(I,"A").Value = "red"
    End If
    Next i

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Stuart" <Stuart@discussions.microsoft.com> wrote in message
    news:EA5D5071-A2B2-4CF2-A1DA-641F44288267@microsoft.com...
    > Help - I want to update values in a column, but this is with conditions in
    > other cells e.g.
    > A B C
    > 1 blue Fred
    > 2 black Jim
    > 3 blue Steve
    >
    > change blue to red in column A, where content of B = Fred
    >
    > Can this be done?




  3. #3
    Stuart
    Guest

    Re: Find and replace with condition

    I get an error message when I compile:

    Invalid outside procedure


    "Bob Phillips" wrote:

    >
    > For i = 1 To Cells(Rows.Count,"A").End(xlUp).Row
    > If Cells(i,"A").Value = "blue" And Cells(i,"B").Value = "Fred") Then
    > Cells(I,"A").Value = "red"
    > End If
    > Next i
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "Stuart" <Stuart@discussions.microsoft.com> wrote in message
    > news:EA5D5071-A2B2-4CF2-A1DA-641F44288267@microsoft.com...
    > > Help - I want to update values in a column, but this is with conditions in
    > > other cells e.g.
    > > A B C
    > > 1 blue Fred
    > > 2 black Jim
    > > 3 blue Steve
    > >
    > > change blue to red in column A, where content of B = Fred
    > >
    > > Can this be done?

    >
    >
    >


  4. #4
    Bob Phillips
    Guest

    Re: Find and replace with condition

    You have to put it in a sub

    Sub myMacro()

    'the code

    End Sub

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Stuart" <Stuart@discussions.microsoft.com> wrote in message
    news:9BA1FBAB-EFF4-484F-9F2E-A596CA3511D1@microsoft.com...
    > I get an error message when I compile:
    >
    > Invalid outside procedure
    >
    >
    > "Bob Phillips" wrote:
    >
    > >
    > > For i = 1 To Cells(Rows.Count,"A").End(xlUp).Row
    > > If Cells(i,"A").Value = "blue" And Cells(i,"B").Value = "Fred")

    Then
    > > Cells(I,"A").Value = "red"
    > > End If
    > > Next i
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "Stuart" <Stuart@discussions.microsoft.com> wrote in message
    > > news:EA5D5071-A2B2-4CF2-A1DA-641F44288267@microsoft.com...
    > > > Help - I want to update values in a column, but this is with

    conditions in
    > > > other cells e.g.
    > > > A B C
    > > > 1 blue Fred
    > > > 2 black Jim
    > > > 3 blue Steve
    > > >
    > > > change blue to red in column A, where content of B = Fred
    > > >
    > > > Can this be done?

    > >
    > >
    > >




  5. #5
    Stuart
    Guest

    Re: Find and replace with condition

    Hi,

    I've tried this code, but it doesn't seem to work. It will compile and run,
    but nothing happens. I'd expect cell A1 to change from blue to red, but it
    remains blue. Any more help?!

    Thanks.

    "Bob Phillips" wrote:

    > You have to put it in a sub
    >
    > Sub myMacro()
    >
    > 'the code
    >
    > End Sub
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "Stuart" <Stuart@discussions.microsoft.com> wrote in message
    > news:9BA1FBAB-EFF4-484F-9F2E-A596CA3511D1@microsoft.com...
    > > I get an error message when I compile:
    > >
    > > Invalid outside procedure
    > >
    > >
    > > "Bob Phillips" wrote:
    > >
    > > >
    > > > For i = 1 To Cells(Rows.Count,"A").End(xlUp).Row
    > > > If Cells(i,"A").Value = "blue" And Cells(i,"B").Value = "Fred")

    > Then
    > > > Cells(I,"A").Value = "red"
    > > > End If
    > > > Next i
    > > >
    > > > --
    > > >
    > > > HTH
    > > >
    > > > RP
    > > > (remove nothere from the email address if mailing direct)
    > > >
    > > >
    > > > "Stuart" <Stuart@discussions.microsoft.com> wrote in message
    > > > news:EA5D5071-A2B2-4CF2-A1DA-641F44288267@microsoft.com...
    > > > > Help - I want to update values in a column, but this is with

    > conditions in
    > > > > other cells e.g.
    > > > > A B C
    > > > > 1 blue Fred
    > > > > 2 black Jim
    > > > > 3 blue Steve
    > > > >
    > > > > change blue to red in column A, where content of B = Fred
    > > > >
    > > > > Can this be done?
    > > >
    > > >
    > > >

    >
    >
    >


  6. #6
    Dave Peterson
    Guest

    Re: Find and replace with condition

    If you have Blue or BLUE or BLue or BLUe, it won't work the way you want.

    In VBA, upper and lower case characters are not considered the same.

    Maybe...

    Sub myMacro()

    For i = 1 To Cells(Rows.Count,"A").End(xlUp).Row
    If lcase(Cells(i,"A").Value)= "blue" _
    And lcase(Cells(i,"B").Value) = "fred") Then
    Cells(I,"A").Value = "red"
    End If
    Next i

    end sub



    Stuart wrote:
    >
    > Hi,
    >
    > I've tried this code, but it doesn't seem to work. It will compile and run,
    > but nothing happens. I'd expect cell A1 to change from blue to red, but it
    > remains blue. Any more help?!
    >
    > Thanks.
    >
    > "Bob Phillips" wrote:
    >
    > > You have to put it in a sub
    > >
    > > Sub myMacro()
    > >
    > > 'the code
    > >
    > > End Sub
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "Stuart" <Stuart@discussions.microsoft.com> wrote in message
    > > news:9BA1FBAB-EFF4-484F-9F2E-A596CA3511D1@microsoft.com...
    > > > I get an error message when I compile:
    > > >
    > > > Invalid outside procedure
    > > >
    > > >
    > > > "Bob Phillips" wrote:
    > > >
    > > > >
    > > > > For i = 1 To Cells(Rows.Count,"A").End(xlUp).Row
    > > > > If Cells(i,"A").Value = "blue" And Cells(i,"B").Value = "Fred")

    > > Then
    > > > > Cells(I,"A").Value = "red"
    > > > > End If
    > > > > Next i
    > > > >
    > > > > --
    > > > >
    > > > > HTH
    > > > >
    > > > > RP
    > > > > (remove nothere from the email address if mailing direct)
    > > > >
    > > > >
    > > > > "Stuart" <Stuart@discussions.microsoft.com> wrote in message
    > > > > news:EA5D5071-A2B2-4CF2-A1DA-641F44288267@microsoft.com...
    > > > > > Help - I want to update values in a column, but this is with

    > > conditions in
    > > > > > other cells e.g.
    > > > > > A B C
    > > > > > 1 blue Fred
    > > > > > 2 black Jim
    > > > > > 3 blue Steve
    > > > > >
    > > > > > change blue to red in column A, where content of B = Fred
    > > > > >
    > > > > > Can this be done?
    > > > >
    > > > >
    > > > >

    > >
    > >
    > >


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1