Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Compare and update please help

One trick in this exercise is that it is not necessary to check an
values - just replace the data. This saves a couple of lines of code
and therefore saves process time over large numbers of records.

I have also found that Copy/Paste is faster than writing values t
cells. This code adds the "new" record to the bottom of the data if i
cannot find a match.

'---------------------------------------------------------
Sub transfer_data()
Dim FromSheet As Worksheet
Dim ToSheet As Worksheet
Dim FoundCell As Object
Dim FromRow As Long
Dim ToRow As Long
Dim LastRow As Long
Dim FindValue
Dim PasteRange As Range
'--------------------------
Application.Calculation = xlCalculationManual
Set FromSheet = ActiveSheet
Set ToSheet = Workbooks("Book1.xls").Worksheets("data")
LastRow = ToSheet.Range("A65536").End(xlUp).Row + 1
FromRow = 2
While FromSheet.Cells(FromRow, 1).Value < ""
' find record
FindValue = FromSheet.Cells(FromRow, 1).Value
FromSheet.Range("A" & FromRow & ":H" & FromRow).Copy
Set FoundCell = ToSheet.Columns(1).Find(what:=FindValue)
If FoundCell Is Nothing Then
' add data to bottom of list
Set PasteRange = ToSheet.Range("A" & LastRow)
LastRow = LastRow + 1
Else
' replace data
ToRow = FoundCell.Row
Set PasteRange = ToSheet.Range("A" & ToRow)
End If
ToSheet.Paste Destination:=PasteRange
FromRow = FromRow + 1
Wend
Application.Calculation = xlCalculationAutomatic
MsgBox ("Done")
End Sub
'---------------------------------------------------------------

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Compare and update please help

Thanks Brian that's great!
Every now and then the updates Ireceive have the columns changed
around on me and I have to change them back them back to look like the
Master but the column heading neve change.
Would it be possbile to set it up so that the macro can look for
column heading s and paste the updates appropriately?















BrianB wrote in message ...
One trick in this exercise is that it is not necessary to check any
values - just replace the data. This saves a couple of lines of code -
and therefore saves process time over large numbers of records.

I have also found that Copy/Paste is faster than writing values to
cells. This code adds the "new" record to the bottom of the data if it
cannot find a match.

'---------------------------------------------------------
Sub transfer_data()
Dim FromSheet As Worksheet
Dim ToSheet As Worksheet
Dim FoundCell As Object
Dim FromRow As Long
Dim ToRow As Long
Dim LastRow As Long
Dim FindValue
Dim PasteRange As Range
'--------------------------
Application.Calculation = xlCalculationManual
Set FromSheet = ActiveSheet
Set ToSheet = Workbooks("Book1.xls").Worksheets("data")
LastRow = ToSheet.Range("A65536").End(xlUp).Row + 1
FromRow = 2
While FromSheet.Cells(FromRow, 1).Value < ""
' find record
FindValue = FromSheet.Cells(FromRow, 1).Value
FromSheet.Range("A" & FromRow & ":H" & FromRow).Copy
Set FoundCell = ToSheet.Columns(1).Find(what:=FindValue)
If FoundCell Is Nothing Then
' add data to bottom of list
Set PasteRange = ToSheet.Range("A" & LastRow)
LastRow = LastRow + 1
Else
' replace data
ToRow = FoundCell.Row
Set PasteRange = ToSheet.Range("A" & ToRow)
End If
ToSheet.Paste Destination:=PasteRange
FromRow = FromRow + 1
Wend
Application.Calculation = xlCalculationAutomatic
MsgBox ("Done")
End Sub
'----------------------------------------------------------------


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

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
Compare ENTRIE row in OLD_Sheet.xls and Update the Comments Column Value in NEW.xls vsugadev Excel Discussion (Misc queries) 1 October 4th 10 08:46 AM
Compare two files and update data from another file base on words ina cell separated by commas mishak Excel Worksheet Functions 0 December 9th 09 01:35 AM
Compare and update spreadsheets Boinks Excel Discussion (Misc queries) 1 July 26th 08 12:58 PM
Compare and Update elements from Sheet1 with Sheet2 [email protected] New Users to Excel 3 November 27th 07 04:27 PM
How do I compare cells and if FALSE compare to next cell in EXCEL Cindie Excel Worksheet Functions 0 March 24th 06 05:29 PM


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