Reputation:
I have two excel files.
1st file is big and has a lot of users and their attributes (found in columns )
2nd file is my file with only my users.
The goal is to look at 1st file for the names of that are on 2nd file.
If the name is found there copy it to a csv file and if one of the columns is empty write a comment saying “Column/Attribute is not filled”
How would I go with solving this problem considering the fact that I don’t have that much experience excel advanced features.
Upvotes: 0
Views: 1301
Reputation: 20302
Try it like this.
Sub Compare()
Dim WorkRng1 As Range, WorkRng2 As Range, Rng1 As Range, Rng2 As Range
Set objWorkbook1 = Workbooks.Open("C:\your_path\Book1.xlsx")
Set objWorkbook2 = Workbooks.Open("C:\your_path\Book2.xlsx")
Set objWorksheet1 = objWorkbook1.Worksheets(1)
Set objWorksheet2 = objWorkbook2.Worksheets(1)
Set WorkRng1 = objWorksheet1.UsedRange
Set WorkRng2 = objWorksheet2.UsedRange
For Each Rng1 In WorkRng1
Rng1.Value = Rng1.Value
For Each Rng2 In WorkRng2
If Rng1.Value = Rng2.Value Then
' If match, delete
' your biz logic goes here
Exit For
End If
Next
Next
End Sub
Upvotes: 1
Reputation: 2282
I'm aware that your question is tagged with VBA but what exactly are your requirements here?
For example, it might be worth considering to export the excel spreadsheets to XML files and then use XQuery to retrieve that information. However, I'm not sure whether this fits your needs/requirements in terms of tools/stack.
Upvotes: 0