Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Stuart
 
Posts: n/a
Default 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   Report Post  
Bob Phillips
 
Posts: n/a
Default


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" wrote in message
...
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   Report Post  
Stuart
 
Posts: n/a
Default

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" wrote in message
...
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   Report Post  
Bob Phillips
 
Posts: n/a
Default

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" wrote in message
...
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" wrote in message
...
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   Report Post  
Stuart
 
Posts: n/a
Default

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" wrote in message
...
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" wrote in message
...
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   Report Post  
Dave Peterson
 
Posts: n/a
Default

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" wrote in message
...
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" wrote in message
...
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
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
Find and replace of word causes change of font formatting jwa90010 New Users to Excel 4 July 22nd 05 08:10 PM
find and replace steve Excel Discussion (Misc queries) 1 June 23rd 05 01:43 AM
Find and Replace - Quickest Option? Lindsey M Excel Worksheet Functions 1 March 8th 05 11:34 AM
find replace cursor default to find box luffa Excel Discussion (Misc queries) 0 February 3rd 05 12:11 AM
VB Find and Replace Bony_Pony Excel Worksheet Functions 10 December 6th 04 05:45 PM


All times are GMT +1. The time now is 07:30 PM.

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"