how to check the values in each cell across workbooks?

htoh2

New Member
Joined
Oct 20, 2010
Messages
25
Hi experts,

i'm a novice in vba and hope someone out there can assist me, thanks.

I would like to know how can i compare the values in the cells between 2 workbooks.

For eg.

in Enduser.xls, i have the following 2 columns :

Country code Business Positions
HH1 Manager
HH2 P Manager

In Lookup.xls, i have 2 columns of data:

Country code Company Code
HH1 CC1
HH1 CC2
HH1 CC3
HH2 CD1
HH3 CE3

So when i run the macro, it will check that IF country code in Enduser.xls & Country Code in Lookup.xls = "HH1" , then copy or store the values (CC1,CC2,CC3) in an array so later i can retrieve them.

Pls help

Thanks

Regards,
htoh2
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Use in Enduser workbook

I have assumed your both workbook is placd in same folder

Code:
Sub check()
Dim varArray(100)
Dim cell As Range
Dim i As Long
Dim wbkA    As Workbook
Dim wbkNew  As Workbook
Set wbkA = ThisWorkbook
 
i = 0
Set wbkNew = Workbooks.Open(ThisWorkbook.Path & "\lookup.xls")
With wbkNew.Worksheets("sheet1")
    For Each cell In .Range("A1:A" & .Range("A" & Rows.Count).End(xlUp).Row)
If cell.Value = "HH1" Then
varArray(i) = cell.Offset(, 1).Value
i = i + 1
End If
Next
End With
End Sub
 
Upvote 0
Hi, thank you for your reply. :)

May i check with you if your codes are storing the values into the array?

However,

i've edited to these codes:

Sub check()
Dim varArray(100)
Dim cell As Range
Dim i As Long
Dim wbkA As Workbook
Dim wbkNew As Workbook
Set wbkA = ThisWorkbook

i = 0
Set wbkNew = Workbooks.Open(ThisWorkbook.Path & "\lookup.xls")
With wbkNew.Worksheets("sheet1")
For Each cell In .Range("A1:A" & .Range("A" & Rows.Count).End(xlUp).Row)
If cell.Value = "HH1" Then
varArray(i) = cell.Offset(, 1).Value
i = i + 1
End If
Next
With wbkNew.Worksheets("destinationFile")
ActiveCell.Value = varArray
End With
End With
End Sub

but i could not paste to my destination.

Could you kindly guide me?
Thanks

Regards,
htoh2
 
Upvote 0

Forum statistics

Threads
1,217,382
Messages
6,136,237
Members
450,000
Latest member
jgp19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top