First off, I am extremely new to excel vba. I have some code that works well in one workbook but doesn't work in the workbook I need it in. When using F8, it skips over the portion of the code beginning with If Cells(i, 4) = customername Then
through End If
.
I have searched for several days trying to find an answer online. When I run the macro, the screen flashes but the data disappears. Here is the code I am trying to use, any help will be greatly appreciated.
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