Consulting

Results 1 to 3 of 3

Thread: help speed vba code

  1. #1
    VBAX Tutor CCkfm2000's Avatar
    Joined
    May 2005
    Posts
    209
    Location

    help speed vba code

    Many thanks for looking at this problem

    I need to speed this vba code.

    Original thread http://www.vbaexpress.com/forum/showthread.php?t=9583

    Thanks again

    [vba]Option Explicit
    Dim InvenA As Integer
    Dim InvenB As Integer
    Dim InvenC As Integer
    Sub Inventory()
    Do
    InventoryABC
    lookupInvenoryinfo
    Do While InvenA = InvenB
    InventoryABC
    lookupInvenoryinfo
    Exit Do
    Loop
    Loop Until InvenA = InvenB
    End Sub
    Sub lookupInvenoryinfo()
    Sheets("LANE QUANTITY").Select
    InvenA = ActiveSheet.Range("bx68")
    InvenB = ActiveSheet.Range("bx69")
    InvenC = ActiveSheet.Range("bx70")
    End Sub
    Sub InventoryABC()
    Sheets("Inven1").Select
    InventoryA
    Sheets("Inven2").Select
    InventoryB
    Sheets("Inven3").Select
    InventoryC
    Sheets("LANE QUANTITY").Select
    lookupInvenoryinfo
    If InvenA < InvenB Then
    InventoryA
    End If
    If InvenA < InvenC Then
    InventoryA
    End If
    Sheets("LANE QUANTITY").Select
    lookupInvenoryinfo
    If InvenB < InvenA Then
    InventoryB
    End If
    If InvenB < InvenC Then
    InventoryB
    End If
    Sheets("LANE QUANTITY").Select
    lookupInvenoryinfo
    If InvenC < InvenA Then
    InventoryC
    End If
    If InvenC < InvenB Then
    InventoryC
    End If
    Sheets("LANE QUANTITY").Select
    End Sub
    Sub InventoryA()
    Sheets("Inven1").Select
    Range("A2").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
    End Sub
    Sub InventoryB()
    Sheets("Inven2").Select
    Range("A2").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
    End Sub
    Sub InventoryC()
    Sheets("Inven3").Select
    Range("A2").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
    End Sub[/vba]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This might help

    [vba]


    Option Explicit
    Dim InvenA As Integer
    Dim InvenB As Integer
    Dim InvenC As Integer
    Sub Inventory()
    Do
    InventoryABC
    lookupInvenoryinfo
    Do While InvenA = InvenB
    InventoryABC
    lookupInvenoryinfo
    Exit Do
    Loop
    Loop Until InvenA = InvenB
    End Sub
    Sub lookupInvenoryinfo()
    With Sheets("LANE QUANTITY")
    InvenA = .Range("bx68").Value
    InvenB = .Range("bx69").Value
    InvenC = .Range("bx70").Value
    End With
    End Sub
    Sub InventoryABC()
    InventoryA
    InventoryB
    InventoryC
    lookupInvenoryinfo
    If InvenA < InvenB Then
    InventoryA
    End If
    If InvenA < InvenC Then
    InventoryA
    End If
    lookupInvenoryinfo
    If InvenB < InvenA Then
    InventoryB
    End If
    If InvenB < InvenC Then
    InventoryB
    End If
    lookupInvenoryinfo
    If InvenC < InvenA Then
    InventoryC
    End If
    If InvenC < InvenB Then
    InventoryC
    End If
    End Sub
    Sub InventoryA()
    Sheets("Inven1").Range("A2").QueryTable.Refresh BackgroundQuery:=False
    End Sub
    Sub InventoryB()
    Sheets("Inven2").Range("A2").QueryTable.Refresh BackgroundQuery:=False
    End Sub
    Sub InventoryC()
    Sheets("Inven3").Range("A2").QueryTable.Refresh BackgroundQuery:=False
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor CCkfm2000's Avatar
    Joined
    May 2005
    Posts
    209
    Location
    thanks xld much better with your version.

Posting Permissions

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