Some time ago help from this forum helped me check if an item in one list appeared in another. However I now have a slightly different issue I want to see if one item in a table appears in another. The tables are likely to have a different number of rows and possibly different number of columns. The previous solution provided by KniazidisR compared the results on a row basis which was OK if the number of columns was the same. It compares the entire row and all I want to do is compare one column. I will then delete the row in what for a better term is the new list
tell application “Microsoft Excel”
set Firstlist to value of range (“A3:A7”)
set Secondlist to value of range (“C3:C9”)
end tell
set Test to Secondlist contains {item 1 of Firstlist} --This was the solution the parentheses
log Firstlist
log Secondlist
type or paste code here
What is it you’re trying to do here?
As written, your script seems to do what you ask - compare the value of cell A3 (i.e. “{item 1 of Firstlist}”) to the list of values in C3:C9
OMM, that sets Test to true or false depending on whether the cell value matches or not. Therefore I can’t see what you’re asking.
On a separate note, once change you might consider is:
Instead of:
set Firstlist to value of range (“A3:A7”)
Use:
set Firstlist to value of cells of range (“A3:A7”)
The reason being is that, as written, Firstlist will contain a list of lists:
{ {"Andrew"}, {"Bob"}, {"Catherine"}, {"David"}, {"Elizabeth"} }
whereas the second form will give you a list of the values directly:
{ "Andrew", "Bob", "Catherine", "David", "Elizabeth" }
which is a lot easier to parse (and is why you need the extra parentheses in the comparison line).
1 Like
Thank you , don’t think I explained my issue correctly. I have two tables and they do have a different number of columns, I do not want to compare all the columns but a subset but who I have found new entries I want to transfer all of the columns to the existing worksheet/workbook. As an example say the the master workbook/ worksheet for a want of a better term has 8 columns and the other workbook/worksheet has 6 columns and I want to compare the first 4 columns and transfer the 6 columns in the new workbook to the master.
Not sure that explanation is that clear but hopefully you get the idea.
Not really much clearer.
What do you mean you want to compare columns? Every value in each column? The first value in one column with all the values in a different column?
How do you decide which columns you are going to compare?
What would help immensely would be an example. Can you post a sample spreadsheet (with fake data if need be) or even just screenshots illustrating what you are starting with, what you are trying to do, and what the end result should be?
1 Like