macros运行,但没有数据粘贴

首先,我对excel vba非常陌生。 我有一些代码在一个工作簿中运行良好,但是在我需要的工作簿中不起作用。当使用F8时 ,它跳过以If Cells(i, 4) = customername Then开头的代码部分If Cells(i, 4) = customername Then通过End If

我已经search了几天试图在网上find答案。 当我运行macros,屏幕闪烁,但数据消失。 这里是我试图使用的代码,任何帮助将不胜感激。

 Sub CustomerReport() Dim datasheet As Worksheet Dim reportsheet As Worksheet Dim customername As String Dim finalrow As Integer Dim i As Integer Set datasheet = Sheet3 Set reportsheet = Sheet8 customername = reportsheet.Range("D6").Value reportsheet.Range("C8:M500").ClearContents datasheet.Select finalrow = Cells(Rows.Count, 1).End(xlUp).Row For i = 8 To finalrow If Cells(i, 4) = customername Then Range(Cells(i, 3), Cells(i, 13)).Copy reportsheet.Select Range("C200").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats datasheet.Select End If Next i reportsheet.Select Range("D6").Select End Sub