+ Reply to Thread
Results 1 to 3 of 3

Populate Countif values (Offset) into Array and loop through it

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-20-2014
    Location
    India
    MS-Off Ver
    2013
    Posts
    275

    Populate Countif values (Offset) into Array and loop through it

    Dear all,
    I am working with data in attached file.


    I am struggling hard to populate few values into array. below is what i am trying to achieve.

    1) I am taking countifs values in column E:E
    2) For each values, if CountIfs is >= 2, then i need its offset(0,3) values (Column D:D) to be populated into Dynamic array.
    3) Later i will loop through this array if any Status has string "Updates on".

    Could anyone help advise how can i achieve this.?

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Populate Countif values (Offset) into Array and loop through it

    It's not clear what the final result that you want, but please try this :
    (note : you can remove column E formulas, countifs() is performed by the macro itself)
    Sub Test()
      Dim a(), c As New Collection, strKey As String, i As Long, j As Long, p As Long
      a = Range("A1").CurrentRegion.Resize(, 4).Value
      For i = 2 To UBound(a, 1)
          strKey = a(i, 1) & "|" & a(i, 2) & "|" & a(i, 3)
          On Error Resume Next
             c.Add key:=strKey, Item:=New Collection
          On Error GoTo 0
          c(strKey).Add a(i, 4)
      Next i
      p = 1
      For i = 2 To UBound(a, 1)
          strKey = a(i, 1) & "|" & a(i, 2) & "|" & a(i, 3)
          If c(strKey).Count >= 2 And InStr(1, a(i, 4), "Updates on") > 0 Then
             p = p + 1
             For j = 1 To UBound(a, 2)
                 a(p, j) = a(i, j)
             Next j
          End If
      Next i
      For i = p + 1 To UBound(a, 1)
          For j = 1 To UBound(a, 2)
              a(i, j) = vbNullString
          Next j
      Next i
      Range("G1").Resize(UBound(a, 1), UBound(a, 2)).Value = a
    End Sub
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

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

    Re: Populate Countif values (Offset) into Array and loop through it

    Array x is the one you are looking for.
    Sub test()
        Dim x
        With Cells(1).CurrentRegion
            x = Filter(Evaluate("transpose(if((countifs(" & .Columns(1).Address & "," & .Columns(1).Address & "," & _
            .Columns(2).Address & "," & .Columns(2).Address & "," & .Columns(3).Address & "," & .Columns(3).Address & _
            ")>=2)*(left(" & .Columns(4).Address & ",10)=""updates on""),row(1:" & .Rows.Count & ")))"), False, 0)
            If UBound(x) > -1 Then
                x = Application.Index(.Value, Application.Transpose(x), Evaluate("column(" & .Rows(1).Address & ")"))
            Else
                MsgBox "No matched data"
            End If
        End With
    End Sub

+ 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. [SOLVED] Replace Array values through loop
    By brainzlp in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-24-2016, 10:56 PM
  2. [SOLVED] Assigning array values with a loop
    By Mr. Rogers in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-14-2016, 12:02 PM
  3. Loop new messages containing a table, populate a dynamic array, paste array to Excel
    By laripa in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2013, 07:20 AM
  4. [SOLVED] Loop Through Column, Populate Values In Another Sheet With Matching Identifiers
    By aeg_paul in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-15-2013, 02:10 PM
  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. VBA. Return values offset loop issues
    By Cicada in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-15-2011, 10:06 PM

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