B4andafter
New Member
- Joined
- Aug 9, 2017
- Messages
- 30
- Office Version
- 365
- Platform
- Windows
Hello guys, I have a list of purchase orders (PO's) in sequential order (one below the other) all in excel that begin with a company name in Column A, "Cardiac.." and ends with a "Signature" line also in column A. The PO's data are occupy Column A to Column I. Each purchase order is of different size, i.e. uses up multiple rows. My objective here is if there is the word "Accrue" in Column K on a certain line of the purchase order, I want to copy and paste that particular purchase order and paste it on a different worksheet and have this repeat until final row. Currently I am copying and pasting this manually and it is time consuming.
Also, The company name is always in Column A and 13 rows above the word "Accrue" which is in column K.
Below is the code that I am using but I am getting a Run-time error '13' Type mismatch. Your help is much appreciated.
By the way I have been using Mr. Excel's VBA and Macros book as a guide but this is tricky for me. Thanks in advance.
Sub Accruev2()
Dim datasheet As Worksheet
Dim reportsheet As Worksheet
Dim finalrow As Integer
Dim i As Integer
Dim Accrue As String
'set variables
Set datasheet = Sheet18
Set reportsheet = Sheet21
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To finalrow
If Cells(i, 11) = "Accrue" Then
Set iTempRow = Cells(i, 1).Find(What:="Cardiac*", After:=Cells(i - 14, 1), searchorder:=xlByRows, searchdirection:=xlPrevious)
Set endcell = Cells(i, 1).Find(What:="Signature*", After:=Cells(i, 1), LookIn:=xlValues, LookAt:=xlWhole, searchorder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False, SearchFormat:=False)
Range(Cells(iTempRow, 1), Cells(endcell, 11)).Copy
reportsheet.Select
Range("A10000").End(xlUp).Offset(1, 0).PasteSpecial xlPasteAllUsingSourceTheme
datasheet.Select
End If
Next i
End Sub
Also, The company name is always in Column A and 13 rows above the word "Accrue" which is in column K.
Below is the code that I am using but I am getting a Run-time error '13' Type mismatch. Your help is much appreciated.
By the way I have been using Mr. Excel's VBA and Macros book as a guide but this is tricky for me. Thanks in advance.
Sub Accruev2()
Dim datasheet As Worksheet
Dim reportsheet As Worksheet
Dim finalrow As Integer
Dim i As Integer
Dim Accrue As String
'set variables
Set datasheet = Sheet18
Set reportsheet = Sheet21
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To finalrow
If Cells(i, 11) = "Accrue" Then
Set iTempRow = Cells(i, 1).Find(What:="Cardiac*", After:=Cells(i - 14, 1), searchorder:=xlByRows, searchdirection:=xlPrevious)
Set endcell = Cells(i, 1).Find(What:="Signature*", After:=Cells(i, 1), LookIn:=xlValues, LookAt:=xlWhole, searchorder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False, SearchFormat:=False)
Range(Cells(iTempRow, 1), Cells(endcell, 11)).Copy
reportsheet.Select
Range("A10000").End(xlUp).Offset(1, 0).PasteSpecial xlPasteAllUsingSourceTheme
datasheet.Select
End If
Next i
End Sub