Results 1 to 13 of 13

SpeedUp and Optimize My Code

Threaded View

  1. #1
    Registered User
    Join Date
    07-06-2017
    Location
    Long Island, New York
    MS-Off Ver
    2016
    Posts
    7

    SpeedUp and Optimize My Code

    Sub FillInventoryAcross()
    'This code is the formulas for the Total Inventory, Sales, and Production Data. Just addition formulas.
    Call SpeedUp
    Dim strFormulas(1 To 3) As Variant
    
    With ThisWorkbook.Sheets("Inventory")
    strFormulas(1) = "=SUM(C15,C20,C25,C30,C35,C40)"
    strFormulas(2) = "=SUM(C16,C21,C26,C31,C36,C41)"
    strFormulas(3) = "=SUM(C18,C23,C28,C33,C38,C43)"
    
    .Range("C11:W11").formula = strFormulas(1)
    .Range("C11:W11").FillRight
    .Range("C12:W12").formula = strFormulas(2)
    .Range("C12:W12").FillRight
    .Range("C13:W13").formula = strFormulas(3)
    .Range("C13:W13").FillRight
    End With
    Call SpeedDown
    End Sub
    
    Sub FillInventoryPerLocation()
    'This code will fill in the inventory per location. It will add up all of the sales, movement and production per plant along with the prior days inventory.
    Call SpeedUp
    Dim strformula(1 To 12) As Variant
    
    With ThisWorkbook.Sheets("Inventory")
    strformula(1) = "=IFERROR(IF(TRIM(Inventori!$D:$D)=""L95"",INDEX(Inventori!$E:$E,MATCH(Inventory!$M$3,Inventori!$B:$B,0))+SUM(C16:C19)+C46,0),0)"
    strformula(2) = "=IFERROR(IF(TRIM(Inventori!$D:$D)=""L90"",INDEX(Inventori!$E:$E,MATCH(Inventory!$M$3,Inventori!$B:$B,0)),0)+SUM(C21:C24),0)"
    strformula(3) = "=IFERROR(IF(TRIM(Inventori!$D:$D)=""L91"",INDEX(Inventori!$E:$E,MATCH(Inventory!$M$3,Inventori!$B:$B,0)),0)+SUM(C26:C29),0)"
    strformula(4) = "=IFERROR(IF(TRIM(Inventori!$D:$D)=""L93"",INDEX(Inventori!$E:$E,MATCH(Inventory!$M$3,Inventori!$B:$B,0)),0)+SUM(C31:C34),0)"
    strformula(5) = "=IFERROR(IF(TRIM(Inventori!$D:$D)=""L94"",INDEX(Inventori!$E:$E,MATCH(Inventory!$M$3,Inventori!$B:$B,0)),0)+SUM(C36:C39),0)"
    strformula(6) = "=IFERROR(IF(TRIM(Inventori!$D:$D)=""A78"",INDEX(Inventori!$E:$E,MATCH(Inventory!$M$3,Inventori!$B:$B,0)),0)+SUM(C41:C44),0)"
    strformula(7) = "=C15+Sum(D16:D19)+D46"
    strformula(8) = "=C20+sum(D21:D24)"
    strformula(9) = "=C25+sum(D26:D29)"
    strformula(10) = "=C30+sum(D31:D34)"
    strformula(11) = "=C35+sum(D36:D39)"
    strformula(12) = "=C40+sum(D41:D44)"
    .Range("C15").formula = strformula(1)
    .Range("C20").formula = strformula(2)
    .Range("C25").formula = strformula(3)
    .Range("C30").formula = strformula(4)
    .Range("C35").formula = strformula(5)
    .Range("C40").formula = strformula(6)
    .Range("D15:W15").formula = strformula(7)
    .Range("D15:W15").FillRight
    .Range("D20:W20").formula = strformula(8)
    .Range("D20:W20").FillRight
    .Range("D25:W25").formula = strformula(9)
    .Range("D25:W25").FillRight
    .Range("D30:W30").formula = strformula(10)
    .Range("D30:W30").FillRight
    .Range("D35:W35").formula = strformula(11)
    .Range("D35:W35").FillRight
    .Range("D40:W40").formula = strformula(12)
    .Range("D40:W40").FillRight
    End With
    Call SpeedDown
    End Sub
    
    Sub SumIfSales()
    'This code will pull up all of the sales information for a product. Just a Sumif looking up information that matches Date/SKU. After the code is in the starting cell, it is then dragged accross for all of the other dates.
    Call SpeedUp
    Dim strformula(1 To 6) As Variant
    With ThisWorkbook.Sheets("Inventory")
    strformula(1) = "=(SUMIFS(Sales!$I$1:$I$200000,Sales!$B$1:$B$200000,""L95"",Sales!$D$1:$D$200000,CONCATENATE(Inventory!C$8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VN"")*-1)"
    strformula(2) = "=(SUMIFS(Sales!$I$1:$I$200000,Sales!$B$1:$B$200000,""L90"",Sales!$D$1:$D$200000,CONCATENATE(Inventory!C$8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VN"")*-1)"
    strformula(3) = "=(SUMIFS(Sales!$I$1:$I$200000,Sales!$B$1:$B$200000,""L91"",Sales!$D$1:$D$200000,CONCATENATE(Inventory!C$8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VN"")*-1)"
    strformula(4) = "=(SUMIFS(Sales!$I$1:$I$200000,Sales!$B$1:$B$200000,""L93"",Sales!$D$1:$D$200000,CONCATENATE(Inventory!C$8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VN"")*-1)"
    strformula(5) = "=(SUMIFS(Sales!$I$1:$I$200000,Sales!$B$1:$B$200000,""L94"",Sales!$D$1:$D$200000,CONCATENATE(Inventory!C$8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VN"")*-1)"
    strformula(6) = "=(SUMIFS(Sales!$I$1:$I$200000,Sales!$B$1:$B$200000,""A78"",Sales!$D$1:$D$200000,CONCATENATE(Inventory!C$8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VN"")*-1)"
    .Range("C16:W16").formula = strformula(1)
    .Range("C16:W16").FillRight
    .Range("C21:W21").formula = strformula(2)
    .Range("C21:W21").FillRight
    .Range("C26:W26").formula = strformula(3)
    .Range("C26:W26").FillRight
    .Range("C31:W31").formula = strformula(4)
    .Range("C31:W31").FillRight
    .Range("C36:W36").formula = strformula(5)
    .Range("C36:W36").FillRight
    .Range("C41:W41").formula = strformula(6)
    .Range("C41:W41").FillRight
    End With
    Call SpeedDown
    End Sub
    
    Sub SumIfMovement()
    'This code works in a similar way to the prior code, but looks to match Date/SKU to find product movement.
    Call SpeedUp
    Dim strformula(1 To 6) As Variant
    With ThisWorkbook.Sheets("Inventory")
    strformula(1) = "=(SUMIFS(Sales!$I$1:$I$200000,Sales!$D$1:$D$200000,CONCATENATE(Inventory!C8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VT"",Sales!$O$1:$O$200000,""95"")-SUMIFS(Sales!$I$1:$I$200000,Sales!$D$1:$D$200000,CONCATENATE(Inventory!C8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VT"",Sales!$B$1:$B$200000,""L95""))"
    strformula(2) = "=(SUMIFS(Sales!$I$1:$I$200000,Sales!$D$1:$D$200000,CONCATENATE(Inventory!C8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VT"",Sales!$O$1:$O$200000,""90"")-SUMIFS(Sales!$I$1:$I$200000,Sales!$D$1:$D$200000,CONCATENATE(Inventory!C8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VT"",Sales!$B$1:$B$200000,""L90""))"
    strformula(3) = "=(SUMIFS(Sales!$I$1:$I$200000,Sales!$D$1:$D$200000,CONCATENATE(Inventory!C8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VT"",Sales!$O$1:$O$200000,""91"")-SUMIFS(Sales!$I$1:$I$200000,Sales!$D$1:$D$200000,CONCATENATE(Inventory!C8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VT"",Sales!$B$1:$B$200000,""L91""))"
    strformula(4) = "=(SUMIFS(Sales!$I$1:$I$200000,Sales!$D$1:$D$200000,CONCATENATE(Inventory!C8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VT"",Sales!$O$1:$O$200000,""93"")-SUMIFS(Sales!$I$1:$I$200000,Sales!$D$1:$D$200000,CONCATENATE(Inventory!C8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VT"",Sales!$B$1:$B$200000,""L93""))"
    strformula(5) = "=(SUMIFS(Sales!$I$1:$I$200000,Sales!$D$1:$D$200000,CONCATENATE(Inventory!C8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VT"",Sales!$O$1:$O$200000,""94"")-SUMIFS(Sales!$I$1:$I$200000,Sales!$D$1:$D$200000,CONCATENATE(Inventory!C8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VT"",Sales!$B$1:$B$200000,""L94""))"
    strformula(6) = "=(SUMIFS(Sales!$I$1:$I$200000,Sales!$D$1:$D$200000,CONCATENATE(Inventory!C8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VT"",Sales!$O$1:$O$200000,""78"")-SUMIFS(Sales!$I$1:$I$200000,Sales!$D$1:$D$200000,CONCATENATE(Inventory!C8,Inventory!$M$3),Sales!$AD$1:$AD$200000,""VT"",Sales!$B$1:$B$200000,""A78""))"
    .Range("C17:W17").formula = strformula(1)
    .Range("C17:W17").FillRight
    .Range("C22:W22").formula = strformula(2)
    .Range("C22:W22").FillRight
    .Range("C27:W27").formula = strformula(3)
    .Range("C27:W27").FillRight
    .Range("C32:W32").formula = strformula(4)
    .Range("C32:W32").FillRight
    .Range("C37:W37").formula = strformula(5)
    .Range("C37:W37").FillRight
    .Range("C42:W42").formula = strformula(6)
    .Range("C42:W42").FillRight
    End With
    Call SpeedDown
    End Sub
    Last edited by mwinning8; 07-06-2017 at 12:43 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Optimize a code
    By pezalmendra in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-06-2015, 05:31 PM
  2. Optimize code
    By DarkKnightLupo in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 02-19-2014, 08:58 AM
  3. Optimize a slow code...
    By benoitly in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2013, 01:44 PM
  4. speedup the code for deleting rows
    By maheshwow in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-17-2012, 02:41 PM
  5. Optimize code
    By miso.dca in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-08-2011, 03:35 PM
  6. Optimize Alphabetizing VBA Code
    By NewExcelUser in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2010, 11:51 PM
  7. Optimize VBA code
    By doodlebug in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2007, 07:53 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1