+ Reply to Thread
Results 1 to 6 of 6

Help with Formula / VBA to extract Information from an Array

  1. #1
    Registered User
    Join Date
    12-11-2021
    Location
    Zurich, Switzerland
    MS-Off Ver
    Office 365
    Posts
    25

    Help with Formula / VBA to extract Information from an Array

    Hi all

    I have a specific task I need to program and I am a little stuck on how to do that most efficiently - using FUNCTIONS and/or VBA.

    I have a list of Suppliers (B3:B22), by name, that each supply one or more products, in this case fruit(s) (as shown in array D3:H22).
    The main supplier of a fruit may be indicated by the bold fruit name (D3, D9; D11, E5, E8, E9, E10, as shown in the attached Excel File), but this is not the case at all times (i.e. the bold indication is not mandatory).
    The allocation might be sloppy - a fruit might be listed twice (e.g. Orange in D5 and F5 - highlighted), which needs to be handled correctly).

    Based on the list of all products (fruits) delivered (J3:J30), I would like a single column (K3:K30) which indicates the Main Suppliers - this column marked in red is supposed to be calculated dynamically.

    The rules for this column (K3:K30) are:
    - If there is only one supplier for a fruit, no matter if that fruit is bold or not, this supplier name is shown in this column.
    - If there are more than one supplier for a fruit, if none of the fruits are bold or more than one of the fruits are bold, then the text "No Main Supplier" followed by all supplier names in bracket, separated by a semicolon, is shown.
    - If there are more that one supplier for a fruit and only one fruit is bold, then this supplier name is shown in this column.

    This might be too complex to do?

    Note that I have VBA code to test for bold, which is:

    Function ISBOLD(CellRef As Range)

    ISBOLD = CellRef.Font.Bold

    End Function

    This might be of use, but implementations that do not use it are fine as well.

    Many thanks for your support.

    Cheers,
    Claus.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    12-11-2021
    Location
    Zurich, Switzerland
    MS-Off Ver
    Office 365
    Posts
    25

    Re: Help with Formula / VBA to extract Information from an Array

    Hi all

    Just to be clear, the number of suppliers and fruits can change and hence the solution needs to be dynamic to cope with that.
    Thanks.

    Cheers,
    Claus.

  3. #3
    Registered User
    Join Date
    12-30-2021
    Location
    Toronto
    MS-Off Ver
    365
    Posts
    51

    Re: Help with Formula / VBA to extract Information from an Array

    Are your suppliers dynamic? Or you are fine with fixing them at 20.
    Also, do you want K3:K30 to be dynamic?

  4. #4
    Registered User
    Join Date
    12-11-2021
    Location
    Zurich, Switzerland
    MS-Off Ver
    Office 365
    Posts
    25

    Re: Help with Formula / VBA to extract Information from an Array

    Thanks!

    Suppliers, Products and K3:K30 need to be dynamic.

    Cheers,
    Claus.

  5. #5
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Help with Formula / VBA to extract Information from an Array

    VBA solution.
    Hit arrow "CLICK HERE" to generate list
    code:
    PHP Code: 
    Option Explicit
    Sub FindSuppliers
    ()
    Dim lr&, i&, j&, srng
    Dim dic 
    As Objectkeybol As Booleansup As String
    Set dic 
    CreateObject("Scripting.Dictionary")
    lr Cells(Rows.Count"B").End(xlUp).Row
    rng 
    Range("B3:H" lr).Value
    For 1 To UBound(rng)
        For 
    3 To UBound(rng2)
            If 
    rng(ij) <> "" Then
                bol 
    Cells(21).Font.Bold
                sup 
    rng(i1) & IIf(bol"@""")
                If 
    Not dic.exists(rng(ij)) Then
                    dic
    .Add rng(ij), sup
                
    Else
                    
    dic(rng(ij)) = dic(rng(ij)) & ";" sup
                End 
    If
            
    End If
        
    Next
    Next
    Range
    ("J3:K10000").ClearContents
    Range
    ("J3").Resize(dic.Count2).Value WorksheetFunction.Transpose(Array(dic.keysdic.items))
    rng Range("K3:K" dic.Count 2).Value
    For 1 To UBound(rng)
        
    Split(rng(i1), "@")
        
    Select Case UBound(s)
            Case 
    2
                rng
    (i1) = "No Main Supplier (" Replace(rng(i1), "@""") & ")"
            
    Case 1
                s 
    Split(rng(i1), ";")
                For 
    0 To UBound(s)
                    If 
    Right(s(j), 1) = "@" Then
                        rng
    (i1) = Replace(s(j), "@""")
                        Exit For
                    
    End If
                
    Next
            
    Case 0
                
    If InStr(1rng(i1), ";"Then rng(i1) = "No Main Supplier (" rng(i1) & ")"
        
    End Select
    Next
    Range
    ("K3:K" dic.Count 2).Value rng
    End Sub 
    Attached Files Attached Files
    Quang PT

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Help with Formula / VBA to extract Information from an Array

    MacClaus,

    Here's how I read your problem.
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Formula/Macro to extract information of certain cells
    By bror31 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2022, 03:54 AM
  2. Formula to extract information from a table
    By viewotst in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-05-2021, 07:44 AM
  3. Extract values with array formula/non-array formula
    By bjnockle in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-29-2020, 11:11 AM
  4. Formula to structure messy CSV export and extract key information
    By downcrusher in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-31-2018, 08:04 AM
  5. Need a Formula to extract information from one sheet to another
    By slock92 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-03-2016, 02:47 PM
  6. Replies: 5
    Last Post: 06-26-2016, 12:52 AM
  7. Array formula to extract information in-between two dates
    By Kayees in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-25-2013, 05:00 AM

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