Hi,
I have a macro which has to search in a filtered area. However when the filter is on, it searches every row, but I don't want that..
Can anyone tell me how the macro can search only the rows which has been filtered?
I have a macro which has to search in a filtered area. However when the filter is on, it searches every row, but I don't want that..
Can anyone tell me how the macro can search only the rows which has been filtered?
Code:
Sub Doorlooptijd()
Dim orderNr As String
Dim matNr As String
Dim lRow As Long
Dim lRow2 As Long
Dim myRange As String
Dim myRange2 As String
Dim teller As String
Dim lastRow As String
Dim i As Integer
Dim myRange3 As String
Dim datum1 As String
Dim samenv As String
Dim myRange4 As String
Dim zoek As String
Dim zoek2 As String
Sheets("Doorlooptijd").Activate
lastRow = Cells(Rows.Count, "B").End(xlUp).Row
teller = 4
myRange2 = "E" & teller
myRange3 = "B" & teller
myRange4 = "G" & teller
For i = 1 To lastRow
myRange2 = "E" & teller
myRange3 = "B" & teller
myRange4 = "G" & teller
Sheets("Doorlooptijd").Activate
orderNr = Range(myRange3).Value
Sheets("Bron sheet").Activate
ActiveSheet.Range("$A$1:$O$28069").AutoFilter Field:=7, Criteria1:=orderNr
zoek = Range("D" & Rows.Count).End(xlUp).Row
On Error Resume Next
zoek = Selection.SpecialCells(xlCellTypeVisible).Copy
Sheets("test").Activate
Cells.Select
ActiveSheet.Paste
lRow = 0
On Error Resume Next
lRow = Application.WorksheetFunction.Match("T140", Range("D:D"), 0)
On Error GoTo 0
If lRow = 0 Then
On Error Resume Next
lRow = Application.WorksheetFunction.Match("T280", Range("D:D"), 0)
End If
If lRow > 0 Then
datum1 = "B" & lRow
myRange = "D" & lRow
samenv = datum1 & "," & myRange
Range(samenv).Copy
Sheets("Doorlooptijd").Activate
Range(myRange2).Select
ActiveSheet.Paste
End If
Sheets("test").Activate
On Error Resume Next
lRow2 = 0
On Error Resume Next
lRow2 = Application.WorksheetFunction.Match("V600", Range("D:D"), 1)
On Error GoTo 0
If lRow2 = 0 Then
On Error Resume Next
lRow2 = Application.WorksheetFunction.Match("V500", Range("D:D"), 1)
End If
On Error GoTo 0
If lRow2 > 0 Then
datum1 = "B" & lRow2
myRange = "D" & lRow2
samenv = datum1 & "," & myRange
Range(samenv).Copy
Sheets("Doorlooptijd").Activate
Range(myRange4).Select
ActiveSheet.Paste
End If
teller = teller + 1
Sheets("Bron sheet").Activate
ActiveSheet.Range("$A$1:$O$28069").AutoFilter Field:=7
Next i
End Sub