Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 使用IsEmpty并合并空单元格_Excel_Vba_Excel Formula - Fatal编程技术网

Excel 使用IsEmpty并合并空单元格

Excel 使用IsEmpty并合并空单元格,excel,vba,excel-formula,Excel,Vba,Excel Formula,我正在编写代码,搜索包含大量重复项的非常大的excel工作表,我可以轻松地将重复项排序在一起,因为它们都有1个匹配列和ID列。我一直想知道的是为什么IsEmpty不去查看当前单元格,看看它是否为空,以及下一个单元格(副本)是否有数据。然后,包含数据的单元格将合并到空单元格中 我试着用Range和cells作为参数,但都没有用 Private Sub CountDuplicates() Dim i As Integer 'The cell it will use to search Dim id

我正在编写代码,搜索包含大量重复项的非常大的excel工作表,我可以轻松地将重复项排序在一起,因为它们都有1个匹配列和ID列。我一直想知道的是为什么IsEmpty不去查看当前单元格,看看它是否为空,以及下一个单元格(副本)是否有数据。然后,包含数据的单元格将合并到空单元格中

我试着用Range和cells作为参数,但都没有用

Private Sub CountDuplicates()
Dim i As Integer

'The cell it will use to search
Dim idCheck As Range

'The cell it will use to compare text
Dim currentCell As Range

'This will be used to format the "Changes" column
Dim rowNumberValue As Integer, columnNumberValue As Integer, rowBelow As Integer
placement = 0
colNum = 3

rowNumberValue = ActiveCell.Row
columnNumberValue = ActiveCell.Column
rowBelow = ActiveCell.Row + 1

'Searches by ID column
For Each idCheck In Worksheets("Sheet1").Range("B2:B1000")

   'This checks to find duplicate ID rows
   If idCheck.Value = idCheck.Offset(-1, 0).Value Then

         'Goes from each column starting from the ID column (H = 7th letter in alphabet and H is the last column)
         For colNum = 3 To 7

            'Checks to see if the cell has no value but the duplicate does
            If IsEmpty(Range(Cells(rowNumberValue, colNum))) = True And IsEmpty(Range(Cells(rowNumberValue + 1, colNum))) = False Then
               Range(Cells(rowNumberValue, colNum), Cells(rowBelow, colNum)).Merge
因此,理想情况下,如果一行有一个单元格缺少数据,而另一行有数据,则将数据合并/复制到缺少数据的单元格中。

替换如下测试:

IsEmpty(Range(Cells(rowNumberValue, colNum))) = True
与:


您需要的是
运算符,而不是
&
。谢谢@BigBen,不过仍然会收到相同的错误。对象“\u Global”的方法“Range”失败“单元格中实际有什么<代码>IsEmpty
不工作。还有一点是错误的:)@DavidZemens这些单元格因列而异,在文本和数值之间,大多数都是文本。还要注意
Range(单元格(rowNumberValue,colNum)…
不适用于特定的工作表,因此它指的是运行时处于活动状态的任何工作表。@最好的做法是限定
单元格或
区域的工作表是否处于打开状态。在您的情况下,它看起来像是
工作表(“Sheet1”)
。这就是上一位的意思。@BigBen你说得对!如果在适当的位置使用With,代码将受益匪浅。
Cells(rowNumberValue, colNum) = ""