View Single Post
 
Old 02-22-2018, 05:58 PM
RosieSummers RosieSummers is offline Windows 7 64bit Office 2016
Novice
 
Join Date: Feb 2018
Posts: 9
RosieSummers is on a distinguished road
Default

Code:
Sub July()
Dim arr, c, b(), n&
Application.ScreenUpdating = False
Worksheets("July 2018").Range("A4").AutoFilter
Workbooks.Open "C:\Users\sophia.tan\Desktop\MasterPlanData.xlsx", 0, 1
arr = Sheets("Excel").UsedRange
ActiveWorkbook.Close 0
c = Array(0, 2, 13, 14, 7, 8, 11, 1, 9, 10, 16, 17, 20, 22, 15, 30, 27, 28, 29, 3, 4, 39)
d = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 23)
ReDim b(1 To UBound(arr), 1 To 23)

For i = 2 To UBound(arr)
    If arr(i, 13) >= DateSerial(Year:=2018, Month:=7, Day:=1) And arr(i, 12) <= DateSerial(Year:=2018, Month:=7, Day:=31) Then
        n = n + 1
        For j = 1 To UBound(c)
            b(n, d(j)) = arr(i, c(j))
        Next
    End If
Next

With Worksheets("Sheet2")
    .Range("A4:W" & Rows.Count).CurrentRegion.SpecialCells(xlCellTypeVisible).AutoFilter field:=1, Criteria1:="<>OFM"
    .Range("A4:W" & Rows.Count).CurrentRegion.SpecialCells(xlCellTypeVisible).AutoFilter field:=13, Criteria1:="<>Collar & Cuff"
    .Range("A4:W" & Rows.Count).CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).Clear
    .Range("A4:W" & Rows.Count).Resize(UBound(b, 1), UBound(b, 2)) = b
    .AutoFilter.ShowAllData
    .Range("A4").CurrentRegion.Sort key1:=Range("G6"), order1:=xlAscending, Header:=xlYes
    .Range("A4").Select
    End With
Call Fabrication
Application.ScreenUpdating = 1
End Sub
this was my previous code. i wanted the vba code to only clear the range of A4:W however this code would clear the entire row. hence i there was a change.
Reply With Quote