Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
THT THT is offline
external usenet poster
 
Posts: 7
Default Tracking changed cells in two identical worksheets

Hi,

I have two worksheets with the same columns. File 1 is my master sheet with
all my rows of data, while File 2 contains only specific rows in File 1. For
example,

File 1 (1000 rows)
Name... City... Age... Group

File 2 (20 of the 1000 rows)
Name... City... Age... Group

File 2 has the most up-to-date data for the 20 of the 1000 rows. Can I
update the data from File 2 into File 1 (for changed cells only) by using a
macro?

I'm not too familiar with VBA code.

Thanks in advance for your help!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Tracking changed cells in two identical worksheets

Hi,
Try this (on test files!):

Sub FundandCopy()
'
' Replace rows in Sheet1 with corresponding rows in Sheet2
' Assumes unique values e.g names, in each sheet
'
Dim ws1 As Worksheet, ws2 As Worksheet
Dim i As Long, ilastrow1 As Long, ilastrow2 As Long
Dim FindValue As String

Set ws1 = Worksheets("sheet1") ' Master sheet
Set ws2 = Worksheets("sheet2") ' Updates sheet

ilastrow1 = ws1.Cells(Rows.Count, "A").End(xlUp).Row ' Assumes name in
Column A
ilastrow2 = ws2.Cells(Rows.Count, "A").End(xlUp).Row

For i = 2 To ilastrow2 ' Loop through names in sheet2 (row 1 = header)

FindValue = ws2.Cells(i, 1) ' e.g Name

With ws1.Range("a2:a" & ilastrow1) ' find match on name in Sheet1
Set c = .Find(FindValue, LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then ' Copy from sheet 2 to sheet 1
ws2.Rows(i).EntireRow.Copy Destination:=ws1.Cells(c.Row, 1)
Else
MsgBox "Name " & FindValue & " not found"
End If
End With

Next i

Set ws1 = Nothing
Set ws2 = Nothing

End Sub


"THT" wrote:

Hi,

I have two worksheets with the same columns. File 1 is my master sheet with
all my rows of data, while File 2 contains only specific rows in File 1. For
example,

File 1 (1000 rows)
Name... City... Age... Group

File 2 (20 of the 1000 rows)
Name... City... Age... Group

File 2 has the most up-to-date data for the 20 of the 1000 rows. Can I
update the data from File 2 into File 1 (for changed cells only) by using a
macro?

I'm not too familiar with VBA code.

Thanks in advance for your help!

  #3   Report Post  
Posted to microsoft.public.excel.programming
THT THT is offline
external usenet poster
 
Posts: 7
Default Tracking changed cells in two identical worksheets

Thank you so much, it works perfectly!

"Toppers" wrote:

Hi,
Try this (on test files!):

Sub FundandCopy()
'
' Replace rows in Sheet1 with corresponding rows in Sheet2
' Assumes unique values e.g names, in each sheet
'
Dim ws1 As Worksheet, ws2 As Worksheet
Dim i As Long, ilastrow1 As Long, ilastrow2 As Long
Dim FindValue As String

Set ws1 = Worksheets("sheet1") ' Master sheet
Set ws2 = Worksheets("sheet2") ' Updates sheet

ilastrow1 = ws1.Cells(Rows.Count, "A").End(xlUp).Row ' Assumes name in
Column A
ilastrow2 = ws2.Cells(Rows.Count, "A").End(xlUp).Row

For i = 2 To ilastrow2 ' Loop through names in sheet2 (row 1 = header)

FindValue = ws2.Cells(i, 1) ' e.g Name

With ws1.Range("a2:a" & ilastrow1) ' find match on name in Sheet1
Set c = .Find(FindValue, LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then ' Copy from sheet 2 to sheet 1
ws2.Rows(i).EntireRow.Copy Destination:=ws1.Cells(c.Row, 1)
Else
MsgBox "Name " & FindValue & " not found"
End If
End With

Next i

Set ws1 = Nothing
Set ws2 = Nothing

End Sub


"THT" wrote:

Hi,

I have two worksheets with the same columns. File 1 is my master sheet with
all my rows of data, while File 2 contains only specific rows in File 1. For
example,

File 1 (1000 rows)
Name... City... Age... Group

File 2 (20 of the 1000 rows)
Name... City... Age... Group

File 2 has the most up-to-date data for the 20 of the 1000 rows. Can I
update the data from File 2 into File 1 (for changed cells only) by using a
macro?

I'm not too familiar with VBA code.

Thanks in advance for your help!

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
Identical Cells in Multiple Worksheets in one Workbook. Randy Excel Worksheet Functions 4 October 1st 09 12:45 AM
How do I compare two worksheets to see if they're identical? sdg105 Excel Discussion (Misc queries) 5 September 26th 08 12:57 PM
Why did Excel create two identical worksheets? ajones1978 Excel Discussion (Misc queries) 3 July 2nd 08 03:31 PM
How do I match identical data from two different worksheets in one Myrto New Users to Excel 1 November 14th 06 06:37 PM
Protection of identical cells on multiple worksheets shawnlacey Excel Worksheet Functions 6 May 16th 06 09:08 PM


All times are GMT +1. The time now is 11:38 PM.

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"