types不匹配VBA检查单元值

我想明白为什么我得到types不匹配的错误:

这是我有的function,基本上它是从工作表复制到另一个,然后删除复制的单元格的第一个字符:

Sub copyBackFormulas() Application.ScreenUpdating = False Application.EnableEvents = False 'iterate through all worksheets Dim WS_Count As Integer WS_Count = ActiveWorkbook.Worksheets.Count Dim I As Integer For I = 1 To WS_Count Dim ws1 As Worksheet Set ws1 = ThisWorkbook.Worksheets(I) 'if sheet contains evdre Set d = ws1.Cells.Find("EVDRE:OK") If Not d Is Nothing Then 'copy back all formulas except from current view Dim wsTarget As Worksheet Set wsTarget = ws1 nameHidden = ActiveSheet.Name & "_BPCOffline" Sheets(nameHidden).Visible = True Dim wsSource As Worksheet Set wsSource = Sheets(nameHidden) For Each c In wsSource.UsedRange.Cells If Left(c.Value, 1) = "_" Then If Left(c.Value, 7) = "_=EVCVW" Then Else c.Copy wsTarget.Range(c.Address) End If End If Next 'Remove underscore For Each c In wsTarget.UsedRange.Cells If Left(c.Value, 1) = "_" Then c.Formula = Right(c.Value, Len(c.Value) - 1) End If Next wsSource.Visible = xlSheetHidden End If Range("A1").Select Next I Application.CutCopyMode = False Application.ScreenUpdating = True Application.EnableEvents = True End Sub 

我有几张纸可能需要复制。 重点是,我得到types不匹配错误的行: If Left(c.Value, 1) = "_" Then ,如果我从其他工作表开始运行macros它只是完美的作品,或者只是做正确的操作在其中一张而不是其他的。 我不明白是什么让它在某个时候起作用,什么不起作用。 任何input是高度赞赏

编辑:我认为这个问题与事实,macros可能没有find第一个条件If Left(c.Value, 1) = "_" Then

您不能复制具有错误值的粘贴公式

如果你想跳过错误的单元格,你需要另一个If … End if block:

 If Not Iserror(c.Value) Then ... End if 

正如Rory在评论中所解释的那样