Results 1 to 12 of 12

Thread: Multi-condition function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,476
    Location
    A different methodology
    [vba]
    Option Explicit
    Option Base 1
    Sub TestSpeed()
    Dim arrData
    Dim arrNeed
    Dim arrPackCat()
    Dim rwData As Long, Rws As Long, i As Long
    Dim x As Long, y As Long
    Dim Rng As Range

    'get data ranges
    With Sheets("Need")
    Set Rng = Range(.Cells(7, 1), Cells(Rows.Count, 1).End(xlUp)).Resize(, 14)
    End With
    Rng.Columns("C:N").ClearContents
    arrNeed = Rng
    With Sheets("Data")
    arrData = Range(.Cells(2, 4), .Cells(Rows.Count, 4).End(xlUp)).Resize(, 19)
    End With
    'Clear old data

    'create concatenated list
    Rws = UBound(arrNeed)
    ReDim arrPackCat(Rws)
    For i = 1 To Rws
    arrPackCat(i) = arrNeed(i, 1) & arrNeed(i, 2)
    Next
    'Read from Data, check destination row & add to array position
    rwData = UBound(arrData)
    For i = 1 To rwData
    x = Application.Match(arrData(i, 1) & arrData(i, 2), arrPackCat, 0)
    For y = 1 To 12
    arrNeed(x, y + 2) = arrNeed(x, y + 2) + arrData(i, y + 7)
    Next
    Next
    'Write result to sheet
    Rng = arrNeed
    End Sub

    [/vba]
    Last edited by mdmackillop; 05-02-2009 at 07:45 AM. Reason: Sample and code revised
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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