比较具有相同数量的单元格的两个行范围 [英] compare two row ranges with same number of cells

查看:381
本文介绍了比较具有相同数量的单元格的两个行范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    Sub compareRange()
        If Worksheets("Sheet1").Range("A14:C14") = Worksheets("Sheet1").Range("A15:C15") Then
            MsgBox "Two Ranges are the same"
        End If
        'MsgBox "Two Ranges are the same"
    End Sub

给予A14:C14(1,2,3)和A15:C15(1,2,3)具有相同的值,我得到类型不匹配错误。
我想如何比较这样的两个范围?

Giving that A14:C14(1,2,3) and A15:C15(1,2,3) has same values, i am getting a type mismatch error. How am i suppose to compare two ranges like this?

推荐答案

你不能这样做。这不是范围如何工作。您需要使用某种for循环遍历范围中的每个单元格。您可能需要添加支票,以便发现单元格数不相等的情况(显然,如果是这种情况,则范围是不同的)。

You just can't do this. This is not how ranges work. You need to iterate through each cell in the ranges using some kind of for loop. You may want to add checks so that you spot cases where the number of cells is not equal (obviously the ranges are different if that is the case).

这篇关于比较具有相同数量的单元格的两个行范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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