If condition

  • Thread starter Thread starter ranjan.khan
  • Start date Start date
R

ranjan.khan

I have 2 workbooks: wkbook1 and wkbook2

Each workbook has only one column (column A) with content.

There are 10 rows with numbers in them. Sometimes these rows will vary
depending on the updates. I.e. wkbook1 may have 5 rows of content, but
wkbook2 may have 8 rows of content. Keep in mind that the content is
only in Column A of both workbooks.

I want to be able to compare both workbooks to see if the content in
their respective Column A match. If there is a number (that is in
wkbook2) that doesn't match what is in wkbook1, then I want to
highlight with yellow those cells in wkbook2.

For example here is the content of both workbooks:

wkbook1 wkbook2
23 23
15 15
66 66
24 24
16
19


Notice that wkbook2 has 2 more different numbers in its column. 16 and
19
What I want to do now is to highlight those 2 cells with yellow.

NOTE: wkbook1 will always be a subset of wkbook2.

Can you provide a VBA code for this?

Thanks.
 
You probably meant workSHEETS?

Sub comparecols()
On Error Resume Next
For Each c In Sheets("sheet3").Range("j1:j4")
If Sheets("a").Range("j1:j4").Find(c) = True Then
'MsgBox c
c.Interior.ColorIndex = 6
End If
Next c
End Sub
 
You probably meant workSHEETS?

Sub comparecols()
On Error Resume Next
For Each c In Sheets("sheet3").Range("j1:j4")
If Sheets("a").Range("j1:j4").Find(c) = True Then
'MsgBox c
c.Interior.ColorIndex = 6
End If
Next c
End Sub

I did mean that I have 2 workbooks. Each workbook has content on
Sheet1 in Column A.

Could you please revised the VBA Code.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top