即使有空格,XlcelltypeBlanks也无法正常工作

时间:2020-10-15 15:13:46

标签: excel vba copy-paste

我有下面的代码,如果“ B”列中有空格,那么它将与“ AH”列中的相应单元格进行检查,如果AH-单元格中的数据包含 AB ,则它应该复制到“ B”列中的空白单元格。即使存在空白单元格,代码仍然会引发运行时错误-1004(未找到任何单元格)@ rng1.SpecialCells(xlCelltypeBlanks)。

Sub A()
Dim sh as worksheet
Din rng1 as Range, LstRw as Long, c1 as Range
Set sh = Activesheet
With sh
  LstRw = Range("A1").currentregion.rows.count
For I = 2 To LstRw
Next I
  Set rng1 = .Range("B1").CurrentRegion.offset(1).Resize(LstRw,1)
 For Each C1 in rng1.SpecialCells(xlCelltypeBlanks)
 If c1.offset(,32) Like "*AB*" Then
    c1 = c1.offset(,32)
 End if
Next c1
End with
End sub
  

0 个答案:

没有答案