I have a string in the cell "A1" and another string in the cell "A2" of Sheet2 which I take them using the LEFT Function. These are changing at every import. I'm trying to find the first string in the column "AP" and the second string in the column "AA" of Sheet1 and sort the sheet by these values. Then I want to copy the entire Sheet1 and paste it in Sheet2. My code gives me nothing. Why is wrong?
Sub rc1()
Dim lastrow As Long
Dim i As Integer, icount As Integer
Dim j As Integer, jcount As Integer
Dim LResult As String
LResult = Sheets("Sheet2").Range("A1")
LResult = Left(LResult, 4)
JResult = Sheets("Sheet2").Range("A2")
JResult = Left(JResult, 2)
lastrow = Sheets("Sheet1").Range("A30000").End(xlUp).Row
Sheets("Sheet2").Activate
Sheets("Sheet2").Range("B2:AQ" & lastrow).Select
Selection.ClearContents
icount = 1
For i = 2 To lastrow
For j = 2 To lastrow
If InStr(1, LCase(Sheets("Sheet1").Range("AP" & i)), LCase(LResult)) <> 0 And InStr(1, LCase(Sheets("Sheet1").Range("AA" & j)), LCase(JResult)) <> 0 Then
icount = icount + 1
Sheets("Sheet2").Range("B" & icount & ":AQ" & icount) = Sheets("Sheet1").Range("A" & i & ":AP" & i).Value
End If
Next j
Next i
End Sub