+ Reply to Thread
Results 1 to 5 of 5

Values from Array, populate into Cell

Hybrid View

  1. #1
    Registered User
    Join Date
    03-31-2014
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    48

    Values from Array, populate into Cell

    Hi all,
    I have coded following macro, it is working when I save the values to immediate window, but don't know how to populate the values, delimited with "," into one cell. Basically I look for "Active" in a column, and if found, go 4 cells to the left and take the info from there...
    Could you help please?
    HTML Code: 

  2. #2
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: Values from Array, populate into Cell

    Public Sub Compile()
    Dim Active() As Variant
    Dim i, strng As String
    ReDim Active(Range("G9:G24").Cells.Count)
    For Each Zelle In Range("G9:G24")
    If InStr(1, Zelle, "Active") <> 0 Then
    Active(i) = Zelle.Offset(0, -4)
    End If
    i = i + 1
    Next Zelle
    strng = ""
    For i = LBound(Active) To UBound(Active)
        If Trim(Active(i)) <> "" Then
            If strng = "" Then
                strng = Active(i)
            Else
                strng = strng & "," & Active(i)
            End If
        End If
    Next i
    End Sub

  3. #3
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Values from Array, populate into Cell

    You can also use the Join method.

    Dim Active() As Variant
    Dim i
    ReDim Active(Range("G9:G24").Cells.Count)
    For Each Zelle In Range("G9:G24")
    If InStr(1, Zelle, "Active") <> 0 Then
    Active(i) = Zelle.Offset(0, -4)
    End If
    i = i + 1
    Next Zelle
    
    Debug.Print Join(Active, ",") 'shows info in Immediate Window
    Range("G25").Value = Join(Active, ",") 'Print into cell G25
    End Sub

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

    Re: Values from Array, populate into Cell

    Do you mean?
        Dim Active() As Variant
        Dim i As Long, Zelle As Range
        ReDim Active(Range("G9:G24").Cells.Count)
        For Each Zelle In Range("G9:G24")
            If InStr(1, Zelle, "Active") <> 0 Then
                Active(i) = Zelle.Offset(0, -4)
                i = i + 1
            End If
        Next Zelle
        ReDim Preserve Active(i - 1)
        MsgBox Join(Active, ",")

  5. #5
    Registered User
    Join Date
    03-31-2014
    Location
    Germany
    MS-Off Ver
    Excel 2003
    Posts
    48

    Re: Values from Array, populate into Cell

    thank you all

+ 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. Populate Countif values (Offset) into Array and loop through it
    By mchilapur in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-16-2017, 05:55 AM
  2. [SOLVED] Populate one array from another array and print new array as a range
    By Kaden265 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2014, 07:52 AM
  3. [SOLVED] Populate a cell based on a value being found in an array
    By minotour in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-21-2013, 11:06 AM
  4. [SOLVED] Populate Listbox with all rows of a dynamic array where elements of a single array match.
    By Tayque_J_Holmes in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-07-2012, 04:54 AM
  5. [SOLVED] Populate ComboBox from array criteria from Worksheet Values
    By Foreverlearning in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-07-2012, 02:34 PM
  6. [VBA] Populate Array with Range Values applying an IF criteria
    By Eldexoly in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2011, 01:51 PM
  7. Macro - auto populate the values based on previous cell values
    By Avinash Kumar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-05-2009, 02:02 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