Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find and Replace Data from one into another

Hello

I have two excel file id.xls and amount.xls

ID.xls format

ID Amount
12345 100
54321 200
11111 250
33333 500

Amount.xls format
Column A Amount

Total 12345

Total 11111

Total 33333


I want the macro to find the ID from id.xls and replace the amount from
ID into amount.xls, and if it couldn't find the id in amount.xls it has
to skip and find the next id till the eof in id.xls

Thanks for any suggestion.


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Find and Replace Data from one into another

Hi

Unfortunately I am not completely clear on how you are laying out the
information in the Amount spreadsheet, so I have assumed that column A
contains something like "Total 11111" and the total will be inserted in to
Column B. Here is a small sample that demonstrates this (it assumes that
the workbooks are open etc):
Sub Replace()
Dim IDRange As Range
Dim AmountRange As Range
Dim cell As Range

'Identify range containing ID's
Set IDRange = Workbooks("Id.xls").Sheets("Sheet1").Range("A1")
Set IDRange = Range(IDRange, IDRange.End(xlDown))

'Identify range containing Summary Data
Set AmountRange = Workbooks("Amount.xks").Sheets("Sheet1").Range("A1 ")
Set AmountRange = Range(AmountRange, AmountRange.End(xlDown))

'Loop through
For Each cell In IDRange
InsertAmount AmountRange, cell
Next
End Sub

Sub InsertAmount(RangeToSearch As Range, IDRange As Range)
Dim MatchRange As Range
Dim strid As String
On Error GoTo done

'Get text of Id
strid = Trim(Str(IDRange))

'Search for range containing the Id
Set MatchRange = RangeToSearch.Find(strid)

'Put value to the right of the id in the cell to the right of the
matching range
MatchRange.Offset(0, 1).Value = IDRange.Offset(0, 1).Value

done:
End Sub

Hope this helps!

Regards
Jane Pratt
Developer Tools Support
Microsoft UK

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.

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 with formated data Jocelyn[_2_] Excel Worksheet Functions 1 February 5th 09 04:25 PM
find and replace data Rob Excel Worksheet Functions 3 September 23rd 08 12:54 AM
find and replace - replace data in rows to separated by commas msdker Excel Worksheet Functions 1 April 15th 06 01:00 AM
How to find/replace data in column Rock Excel Discussion (Misc queries) 3 November 16th 05 02:28 AM
How to find/replace data in column Rock New Users to Excel 4 November 15th 05 10:52 PM


All times are GMT +1. The time now is 08:00 AM.

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"