kuldeepjainesl
Member
Hello, i am using this code to filter the desired row from one sheet to another. Now my code is giving me error on the line below while pasting data. i need help to understand & sort out.
Whole code is as follows :
Code:
With WherePaste
.Resize(Row_Counter, Number_Of_Columns).Value = Application.Transpose(Tmp)
Whole code is as follows :
Code:
Public Sub Filter_Failure_Data()
Dim LastLig As Long, Number_Of_Rows As Long, Row_Counter As Long, i As Long
Dim Row_Array As Variant, Record_Array As Variant, Tmp() As Variant
Dim Customer_Name As String, Additional_Check As String
Dim Number_Of_Columns As Integer, j As Integer
Dim Check_Date As Double
Dim WherePaste As Range
Dim User_Input As Byte
Application.ScreenUpdating = True
With ThisWorkbook.Worksheets("Failure data").Range("Failure_Data")
Number_Of_Rows = .Rows.Count
Record_Array = ThisWorkbook.Worksheets("Dashboard").Range("A21:G21").Value
Number_Of_Columns = .Columns.Count
Row_Array = .Value
For i = 2 To Number_Of_Rows
Application.StatusBar = Format(i / Number_Of_Rows, "0%")
Customer_Name = Row_Array(i, 33)
Check_Date = CDbl(Row_Array(i, 4))
Additional_Check = Row_Array(i, 15) ' Additional check row will be defind (Here it is Cat-code)
If Customer_Name = Record_Array(1, 1) Then
If Check_Date >= CDbl(Record_Array(1, 3)) And Check_Date <= CDbl(Record_Array(1, 5)) Then
If Record_Array(1, 7) = "" Or Left(Additional_Check, 10) = Record_Array(1, 7) Then
Row_Counter = Row_Counter + 1
ReDim Preserve Tmp(1 To Number_Of_Columns, 1 To Row_Counter)
For j = 1 To Number_Of_Columns
Select Case j
Case 4, 44: Tmp(j, Row_Counter) = CDbl(Row_Array(i, j))
Case Else: Tmp(j, Row_Counter) = Row_Array(i, j)
End Select
Next j
End If
End If
End If
Next i
End With
If Row_Counter > 0 Then
With ThisWorkbook.Worksheets("Filtered Failure Data")
User_Input = MsgBox("Do you wish to APPEND to earlier data ( Y/N ) ; NO means earlier data will be overwritten !", vbYesNo)
If User_Input = vbYes Then
Set WherePaste = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
Else
LastLig = .Cells(.Rows.Count, "A").End(xlUp).Row
If LastLig >= 2 Then .Rows("2:" & LastLig).ClearContents
Set WherePaste = .Range("A2")
End If
End With
With WherePaste
.Resize(Row_Counter, Number_Of_Columns).Value = Application.Transpose(Tmp)
.Offset(0, 3).Resize(Row_Counter, 1).NumberFormat = "dd/mm/yy" 'column 4 is date
.Offset(0, 43).Resize(Row_Counter, 1).NumberFormat = "dd/mmm/yyyy" 'column 44 is date
End With
Set WherePaste = Nothing
MsgBox "Procedure Over , " & Row_Counter & " records copied / pasted"
Else
MsgBox "Nothing copied / pasted"
End If
Application.StatusBar = False
End Sub