比较excel VBA中两列中的数据 [英] Comparing data in two columns in excel VBA

查看:725
本文介绍了比较excel VBA中两列中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较excel 2007 vba中两列中的值。


基本上,如果A列中存在的B列中不存在单元格值,则将该值添加到B列的末尾。


excel vba的新手。非常感谢任何帮助。


谢谢

Hi, I would like to compare values in two columns in excel 2007 vba.

Basically if a cell value doesn''t exist in column B that exists in column A then add the value to the end of column B.

Quite new to excel vba. Would appreciate any help.

Thanks

推荐答案

你需要处理trhough列A并检查B列的每个值(使用查找())。任何未找到的项目都需要通过转到B列底部下方的单元格添加,然后使用 Ctrl-UpArrow 的代码(结束(xlUp))获取ccolumn B中使用的最后一个单元格,然后沿着列B下面的第一个未使用单元格向下移动一个单元格。这是来自A列单元格的值的位置。


下面的代码说明了可以处理的一种方法:

You need to process trhough column A and checking each value against column B (using Find()). Any items not found need to be added by going to the cell below the bottom of column B, then using the code for Ctrl-UpArrow (which is End(xlUp)) to get the last cell used in ccolumn B, then going down one cell for the first unused cell below column B. This is where the value from the cell from column A is placed.

The code below illustrates one way this could be handled :

展开 | 选择 | Wrap | 行号


非常感谢快速,详细响应。我尝试了你的代码,而不是仅添加包含差异的单元格,整个范围A被附加到结束或范围B.有没有办法我们只能在范围A的单元格中创建值,而不是范围B,附加到范围B?


再次感谢。
Thanks so much for the quick, detailed response. I tried out your code and instead of only appending cells that contain differences, the entire range A is being appended to the end or range B. Is there a way that we can make only values in the cell in range A, that are not in range B, append to range B?

Thanks again.


这很难说。它对我来说很完美。你能说明你正在使用的数据吗?甚至可能附上你的测试电子表格?
That''s hard to say. It works perfectly for me. Can you give an indication of the data you''re working with? Maybe even attaching your test spreadsheet?


这篇关于比较excel VBA中两列中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆