LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Search and Replace Rows

Hi, try this code, it scans sheet1 finds the first match on sheet 2 and
copies columns B
& C to sheet 2
change references to suit your needs.

'-----------------------------------------------------------------
Sub Update()
Application.ScreenUpdating = False

Dim wsNew As Worksheet, wsOld As Worksheet
Dim xLastRowNew As Long, xLastRowOld As Long
Dim xRN As Long, xRO As Long, XUpdates As Long

Set wsNew = Sheets(1)
Set wsOld = Sheets(2)

' use column 1 ("A") to get last row of data on each sheet
xLastRowNew = wsNew.Cells(Rows.Count, 1).End(xlUp).Row
xLastRowOld = wsOld.Cells(Rows.Count, 1).End(xlUp).Row

' scan new data - assumes first data row is row 1
XUpdates = 0
With wsNew
For xRN = 1 To xLastRowNew
For xRO = 1 To xLastRowOld
' check for match
If .Cells(xRN, 1) = wsOld.Cells(xRO, 1) Then
' copy values chosen to copy items in columns 2 and 3
wsOld.Cells(xRO, 2) = .Cells(xRN, 2)
wsOld.Cells(xRO, 3) = .Cells(xRN, 3)
XUpdates = XUpdates + 1
Exit For
End If
Next xRO
Next xRN
End With
Application.ScreenUpdating = True

MsgBox "Completed - Updated: " & CStr(XUpdates)

End Sub



--
Cheers
Nigel



"MaddMax" wrote in message
...
I have two tables of data, one small with about ten rows of data and the
other thousdands of rows long. I want to lookup the records in the smaller
table in the larger table and where there is a match, replace the record

in
the larger table with the one from the smaller table. I would need to

select
a record from the small table, go over to the sheet with the larger table

and
do a lookup of that record, paste when there is a match and return to the
small table for the next record.

Any pointers? Thanks.



 
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 - replace data in rows to separated by commas msdker Excel Worksheet Functions 1 April 15th 06 01:00 AM
Search and replace Subu Excel Worksheet Functions 4 June 9th 05 07:01 PM
Search and Replace Eric[_6_] Excel Programming 3 July 13th 04 09:44 AM
Search & Replace John Keturi Excel Programming 4 May 31st 04 01:37 AM
Search & Replace John Keturi Excel Programming 2 May 28th 04 05:11 AM


All times are GMT +1. The time now is 11:20 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"