erutherford
Active Member
- Joined
- Dec 19, 2016
- Messages
- 458
found this piece code and its exactly as presented. It works in the provider demo, but not in my new workbook.
Error occurs at the bold red print (object define error)
Error occurs at the bold red print (object define error)
Rich (BB code):
Sub search_and_extract_singlecriteria()
Dim datasheet As Worksheet
Dim reportsheet As Worksheet
Dim typename As String
Dim finalrow As Integer
Dim i As Integer
'set variables
Set datasheet = Sheet1
Set reportsheet = Sheet2
typename = reportsheet.Range("B2").Value
'clear old data
reportsheet.Range("A5:L100").ClearContents
'goto datasheet and start searching and copying
datasheet.Select
finalrow = Cells(Rows.Count, 1).End(x1Up).Row
For i = 2 To finalrow
If Cells(i, 2) = typename Then
Range(Cells(i, 1), Cells(i, 12)).Copy
reportsheet.Select
Range("A200").End(x1Up).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats
datasheet.Select
End If
Next i
reportsheet.Select
Range("B2").Select
End Sub