Hello,
I'm only new to VBA and have been able to get some pretty cool stuff done to my database for my transport company.
I am trying to copy data based from my data sheet "Data" to report sheet "Pre Alert" based on 2 criteria's selected on "Pre Alert" sheet.
The code have is below. When I run the code it does everything except copy and paste.
Any help would be greatly apricated
Dale
Option Explicit
Sub Extract_Data()
Dim datasheet As Worksheet
Dim reportsheet As Worksheet
Dim jobstatus As String
Dim agent As String
Dim finalrow As Integer
Dim i As Integer
Set datasheet = Sheet1
Set reportsheet = Sheet8
jobstatus = reportsheet.Range("C3").Value
agent = reportsheet.Range("E3").Value
reportsheet.Range("B6:W200").ClearContents
datasheet.Select
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 5 To finalrow
If Cells(i, 3) = jobstatus And Cells(i, 5) = agent Then
Range(Cells(i, 2) And Cells(i, 3) And Cells(i, 4) And Cells(i, 5) And Cells(i, 6) And Cells(i, 8) And Cells(i, 9) And Cells(i, 10) And Cells(i, 16) And Cells(i, 18) And Cells(i, 19) And Cells(i, 24) And Cells(i, 38) And Cells(i, 39) And Cells(i, 41) And Cells(i, 43) And Cells(i, 44) And Cells(i, 46)).Copy
reportsheet.Select
Range("B200").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats
datasheet.Select
End If
Next i
reportsheet.Select
Range("C3").Select
End Sub
I'm only new to VBA and have been able to get some pretty cool stuff done to my database for my transport company.
I am trying to copy data based from my data sheet "Data" to report sheet "Pre Alert" based on 2 criteria's selected on "Pre Alert" sheet.
The code have is below. When I run the code it does everything except copy and paste.
Any help would be greatly apricated
Dale
Option Explicit
Sub Extract_Data()
Dim datasheet As Worksheet
Dim reportsheet As Worksheet
Dim jobstatus As String
Dim agent As String
Dim finalrow As Integer
Dim i As Integer
Set datasheet = Sheet1
Set reportsheet = Sheet8
jobstatus = reportsheet.Range("C3").Value
agent = reportsheet.Range("E3").Value
reportsheet.Range("B6:W200").ClearContents
datasheet.Select
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 5 To finalrow
If Cells(i, 3) = jobstatus And Cells(i, 5) = agent Then
Range(Cells(i, 2) And Cells(i, 3) And Cells(i, 4) And Cells(i, 5) And Cells(i, 6) And Cells(i, 8) And Cells(i, 9) And Cells(i, 10) And Cells(i, 16) And Cells(i, 18) And Cells(i, 19) And Cells(i, 24) And Cells(i, 38) And Cells(i, 39) And Cells(i, 41) And Cells(i, 43) And Cells(i, 44) And Cells(i, 46)).Copy
reportsheet.Select
Range("B200").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats
datasheet.Select
End If
Next i
reportsheet.Select
Range("C3").Select
End Sub