Where is the problem in the code that the columns m, n and o are emptied despite specifying the emptying range
sh.Range("C10:L1000").ClearContents
Sub derc()
Dim arr As Variant
Dim temp As Variant
Dim cr As Variant
Dim lr As Long
Dim i As Long
Dim j As Long
Dim C As Long
Dim WS As Worksheet
Dim sh As Worksheet
Dim myArray, targt, targt2
Set Main = Sheets("sh1")
Set sh = Sheets("sh2")
targt = sh.Range("M5").Value & "*"
targt2 = sh.Range("M6").Value & "*"
'targt = "ذك*"
'targt2 = "نا*"
'= = = = = = = = = = = =
sh.Range("C10:L1000").ClearContents
lr = Main.Cells(Rows.Count, 4).End(xlUp).Row
arr = Main.Range("A10:R" & lr).Value
ReDim temp(1 To UBound(arr, 1), 1 To UBound(arr, 2))
cr = Array(2, 4, 5, 7, 9, 10, 11, 12, 15)
j = 1
For i = LBound(arr, 1) To UBound(arr, 1)
'If arr(i, Like targt & "*" _
And arr(i, 89) Like targt2 & "*" Then
'==================
temp(j, 1) = j
For C = LBound(cr) To UBound(cr)
temp(j, C + 2) = arr(i, cr(C))
Next C
j = j + 1
'==================
'==================
Next i
With sh
.Range("C10").Resize(j - 1, UBound(temp, 2)).Value = temp
End With
End Sub
sh.Range("C10:L1000").ClearContents
Sub derc()
Dim arr As Variant
Dim temp As Variant
Dim cr As Variant
Dim lr As Long
Dim i As Long
Dim j As Long
Dim C As Long
Dim WS As Worksheet
Dim sh As Worksheet
Dim myArray, targt, targt2
Set Main = Sheets("sh1")
Set sh = Sheets("sh2")
targt = sh.Range("M5").Value & "*"
targt2 = sh.Range("M6").Value & "*"
'targt = "ذك*"
'targt2 = "نا*"
'= = = = = = = = = = = =
sh.Range("C10:L1000").ClearContents
lr = Main.Cells(Rows.Count, 4).End(xlUp).Row
arr = Main.Range("A10:R" & lr).Value
ReDim temp(1 To UBound(arr, 1), 1 To UBound(arr, 2))
cr = Array(2, 4, 5, 7, 9, 10, 11, 12, 15)
j = 1
For i = LBound(arr, 1) To UBound(arr, 1)
'If arr(i, Like targt & "*" _
And arr(i, 89) Like targt2 & "*" Then
'==================
temp(j, 1) = j
For C = LBound(cr) To UBound(cr)
temp(j, C + 2) = arr(i, cr(C))
Next C
j = j + 1
'==================
'==================
Next i
With sh
.Range("C10").Resize(j - 1, UBound(temp, 2)).Value = temp
End With
End Sub