Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Macro for compare between 2 workbooks and copy adjacent cells

Hello,

I get the macro from GS, it is about compare "account number" column
(column K) in two workbooks, if it is matched account number, column L to N
data
will be copy from week1 unknown sor to week2 unknown sor.xls). May I ask how
to
modify the macro, therefore, not all matched account number, copy data of
column
L to N from week 1 excel to week 2 excel? For example, selection criteria is
column k ( column k, it has several choice: week 1 , week 2, week 3...)

The code and file as following:

https://rapidshare.com/files/4612445...wn_SOR_May.xls

https://rapidshare.com/files/4612445...wn_sor_May.xls


Sub CompareData_CustomerNewUpgrades()
Dim rngSource As Range, rngTarget As Range, rng As Range
Dim lLastRow As Long, lRow As Long, i As Integer

Set rngTarget = Workbooks("week2 unknown
SOR.xls").Sheets("Unknown Customer New
Upgrade").Range("$l:$l")
Set rngSource = ThisWorkbook.Sheets("Unknown Customer New
Upgrade").Range("$l:$l")
lLastRow = rngSource.Rows(rngSource.Rows.Count).End(xlUp).Row

For lRow = 1 To lLastRow
Set rng = rngTarget.Find(What:=rngSource.Cells(lRow), LookAt:=xlWhole)
If Not rng Is Nothing Then
For i = 1 To 2: rng.Offset(, i) = rngSource.Cells(lRow).Offset(, i): Next
End If
Next
End Sub 'CompareData_CustomerNewUpgrades()

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Macro for compare between 2 workbooks and copy adjacent cells

john-lau brought next idea :
Hello,

I get the macro from GS, it is about compare "account number" column
(column K) in two workbooks, if it is matched account number, column L to N
data
will be copy from week1 unknown sor to week2 unknown sor.xls). May I ask how
to
modify the macro, therefore, not all matched account number, copy data of
column
L to N from week 1 excel to week 2 excel? For example, selection criteria
is column k ( column k, it has several choice: week 1 , week 2, week 3...)

The code and file as following:

https://rapidshare.com/files/4612445...wn_SOR_May.xls

https://rapidshare.com/files/4612445...wn_sor_May.xls


Sub CompareData_CustomerNewUpgrades()
Dim rngSource As Range, rngTarget As Range, rng As Range
Dim lLastRow As Long, lRow As Long, i As Integer

Set rngTarget = Workbooks("week2 unknown
SOR.xls").Sheets("Unknown Customer New
Upgrade").Range("$l:$l")
Set rngSource = ThisWorkbook.Sheets("Unknown Customer New
Upgrade").Range("$l:$l")
lLastRow = rngSource.Rows(rngSource.Rows.Count).End(xlUp).Row

For lRow = 1 To lLastRow
Set rng = rngTarget.Find(What:=rngSource.Cells(lRow), LookAt:=xlWhole)
If Not rng Is Nothing Then
For i = 1 To 2: rng.Offset(, i) = rngSource.Cells(lRow).Offset(, i): Next
End If
Next
End Sub 'CompareData_CustomerNewUpgrades()

Thanks


John,

First thing to note is this code is not the same code I sent you,
though the structure is the same.

To apply this to other ranges you need to change the rngTarget and
rngSource refs to match the columns you want to work with.

Also, the counter in the 'For i = 1 to 2...Next' loop (inside the
If...Then) needs to be changed to match the number of columns of data
you want to copy over to the other file. You state here that this is
cols L:N, which means the counter in the this loop needs to be
changed...

FROM '1 To 2'

TO '1 To 3'

...since you want to copy 3 cols of data.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


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 2 column cells and return the adjacent columns cells data of the cell trebor57 Excel Worksheet Functions 1 February 1st 11 02:54 PM
Macro to compare and copy ranges of cells Vanessa[_3_] Excel Programming 4 January 17th 11 10:23 PM
Compare 1 cell to column of cells returning adjacent cells info? Mr. Fine Excel Worksheet Functions 1 April 15th 10 07:36 PM
Macro to compare, find match and copy between workbooks Gary Excel Programming 6 June 5th 08 09:18 PM
compare two text and if equal copy adjacent data Prashanthom Excel Worksheet Functions 1 December 29th 06 03:03 AM


All times are GMT +1. The time now is 09:37 PM.

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"