Consulting

Results 1 to 4 of 4

Thread: VBA loop to replace 5k+ array formulas and circular referencing

  1. #1
    VBAX Newbie
    Joined
    Jul 2016
    Posts
    2
    Location

    VBA loop to replace 5k+ array formulas and circular referencing

    Hi,

    I have built a model which uses array formulas to pull up Invoice IDs and quantities from "Data" tab to "Shipments" tab. Invoice IDs correspond to each Part (Col A) for dates after those listed in Invoice_date column (Col B). This is a multiple occurrence case which continues to look for invoices until we reach the qty specified in Col E of the shipments tab and then moves on to the next line. We can't have any duplicate invoices for each Part (Col A), hence I'm using the last invoice on the row above for the same part as the beginning date for the next invoice. This is resulting in circular referencing and really slowing down the processing.

    Can someone please assist me with a VBA macro to tackle this? I have pulled out a few lines as an example in the attached.
    Many thanks in advance!

    Kay
    Attached Files Attached Files

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    this doesn't help much
    New-1.jpg
    Click to open image in new tab
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Newbie
    Joined
    Jul 2016
    Posts
    2
    Location
    Have you enabled iterative calculations in your Excel?
    I have re-attached the attachment, it shouldn't show the "NAME" error, see below screenshot.

    Screen Shot 2016-07-02 at 12.45.28 AM.jpg
    Attached Files Attached Files

  4. #4
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    I am not entirely sure of your requirements and what I have done doesn't work perfectly but I thought I would post it now because I have run out of time. It might point you in the right direction. I have added an extra sheet called test to avoid overwriting the "shipments" tab.

    [vba]Sub movedata()
    Worksheets("DATA").Select
    inarr = Range(Cells(1, 1), Cells(1321, 4))
    Worksheets("Shipments").Select
    datar = Range(Cells(1, 1), Cells(28, 5))
    Worksheets("test").Select
    Range(Cells(1, 1), Cells(28, 350)) = ""
    outarr = Worksheets("test").Range(Cells(1, 1), Cells(28, 350))
    ' loop round the part numbers asnd quantities on the shipments tab
    For i = 2 To 28
    ' loop through all the incvoices to mathc them up
    pcount = 0
    outcol = 6
    For j = 4 To 1321
    If datar(i, 2) = inarr(j, 1) Then
    ' part number matches
    outarr(i, 2) = datar(i, 2)
    outarr(i, 5) = datar(i, 5)
    pcount = pcount + inarr(j, 4)
    outarr(i, outcol) = inarr(j, 3)
    outcol = outcol + 1
    If pcount >= datar(i, 5) Then
    ' end of row save the date
    If i < 28 Then
    outarr(i + 1, 3) = inarr(j, 2)
    pcount = 0
    outcol = 6
    i = i + 1
    End If

    End If
    End If
    Next j
    Next i


    Worksheets("test").Range(Cells(1, 1), Cells(28, 350)) = outarr


    End Sub


    [/vba]

Posting Permissions

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