Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Searching for a value for and then replacing when found.

Can someone tell me how I would do the following:

- I have numbers in cells E5:E10; A1 and B1
- I would like to search for A1 in cells E5:E10
- On the first instance I find of A1, I would like to replace the
value of that cell with B1

What would be a simple way to write this?

Thanks,
Fish
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Searching for a value for and then replacing when found.

Sub getNfix()
Dim c As Range
Dim ws As Worksheet
Set ws = Worksheets(1) 'Change to actual
For Each c In ws.Range("E5:E10")
If c = Range("a1").Value Then
c.Value = Range("B1").Value
End If
Next

" wrote:

Can someone tell me how I would do the following:

- I have numbers in cells E5:E10; A1 and B1
- I would like to search for A1 in cells E5:E10
- On the first instance I find of A1, I would like to replace the
value of that cell with B1

What would be a simple way to write this?

Thanks,
Fish

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Searching for a value for and then replacing when found.

missed the End Sub on copying.

Sub getNfix()
Dim c As Range
Dim ws As Worksheet
Set ws = Worksheets(1) 'Change to actual
For Each c In ws.Range("E5:E10")
If c = Range("a1").Value Then
c.Value = Range("B1").Value
End If
Next
End Sub

"JLGWhiz" wrote:

Sub getNfix()
Dim c As Range
Dim ws As Worksheet
Set ws = Worksheets(1) 'Change to actual
For Each c In ws.Range("E5:E10")
If c = Range("a1").Value Then
c.Value = Range("B1").Value
End If
Next

" wrote:

Can someone tell me how I would do the following:

- I have numbers in cells E5:E10; A1 and B1
- I would like to search for A1 in cells E5:E10
- On the first instance I find of A1, I would like to replace the
value of that cell with B1

What would be a simple way to write this?

Thanks,
Fish

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Searching for a value for and then replacing when found.

Here is a method using an enumerated search...

Sub ChangeNumber()
Dim X As Long
For X = 5 To 10
If Range("A1").Value = Cells(X, "E").Value Then
Cells(X, "E").Value = Range("B1").Value
Exit For
End If
Next
End Sub

Rick


wrote in message
...
Can someone tell me how I would do the following:

- I have numbers in cells E5:E10; A1 and B1
- I would like to search for A1 in cells E5:E10
- On the first instance I find of A1, I would like to replace the
value of that cell with B1

What would be a simple way to write this?

Thanks,
Fish


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Searching for a value for and then replacing when found.

Thanks JLGWhiz and Rick. I went with the enumerated search and it
worked like a charm.
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
Replacing ? ddate Excel Worksheet Functions 1 January 25th 07 01:31 AM
Searching, matching then searching another list based on the match A.S. Excel Discussion (Misc queries) 1 December 13th 06 05:08 AM
searching names for '*', replacing it with first name [email protected] Excel Programming 3 July 11th 06 08:55 AM
Cell searching and Replacing Graham Feeley Excel Discussion (Misc queries) 3 August 5th 05 04:42 PM
Help Replacing all ( * ) with ( - ) Jeam Excel Discussion (Misc queries) 2 December 3rd 04 03:36 PM


All times are GMT +1. The time now is 06:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"