+ Reply to Thread
Results 1 to 10 of 10

Populate count & sum based on equal to & not equal to factors

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-21-2013
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    122

    Re: Populate count & sum based on equal to & not equal to factors

    Quote Originally Posted by jaslake View Post
    Hi jscalem

    If the Formula approach works for you, fine.

    If not, try this...
    Sub Populate_Chargebacks()
       Dim ws           As Worksheet
       Dim ws1          As Worksheet
       Dim LR           As Long
       Dim Rng          As Range
       Dim Rng1         As Range
       Dim cel          As Range
       Dim c            As Range
    
       Set ws = Sheets("Register")
       Set ws1 = Sheets("Chargebacks")
    
       Application.ScreenUpdating = False
       With ws
          LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                           SearchDirection:=xlPrevious).Row
          If Not .AutoFilterMode Then
             .Rows("1:1").AutoFilter
          End If
    
          .Range("A1:T" & LR).AutoFilter Field:=8, Criteria1:=Array( _
                                                              "NSF", "REFER", "CLOSE", "STOP"), Operator:=xlFilterValues
          .Range("A1:T" & LR).AutoFilter Field:=5, Criteria1:="6"
          .Range("A1:T" & LR).AutoFilter Field:=1, Criteria1:= _
                                         "<>Z99999", Operator:=xlAnd
          Set Rng = .Range(.Cells(2, "D"), .Cells(LR, "D")).SpecialCells(xlCellTypeVisible)
          Set Rng1 = ws1.Columns(1)
          For Each cel In Rng
             Set c = Rng1.Find(Format(cel.Value, "d-mmm-yy"), , xlValues, xlWhole, xlByRows, xlNext, False)
             If Not c Is Nothing Then
                ws1.Cells(c.Row, "F").Value = ws1.Cells(c.Row, "F").Value + 1
                ws1.Cells(c.Row, "G").Value = ws1.Cells(c.Row, "G").Value + cel.Offset(0, 2).Value
             End If
          Next cel
          .AutoFilterMode = False
       End With
       Application.ScreenUpdating = True
    End Sub
    This works PERFECT!!!! Thank you very very much!!!

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Populate count & sum based on equal to & not equal to factors

    You're welcome...glad I could help. Thanks for the Rep.

    If this resolves your issue please mark the Thread as Solved.

    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Contributor
    Join Date
    02-21-2013
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    122

    Re: Populate count & sum based on equal to & not equal to factors

    Quote Originally Posted by jaslake View Post
    You're welcome...glad I could help. Thanks for the Rep.

    If this resolves your issue please mark the Thread as Solved.

    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    So I thought this was solved however when I run the macro if there is nothing that matches this criteria it gives me a runtime error on the following line

    HTML Code: 

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Populate count & sum based on equal to & not equal to factors

    Hi jscalem

    Try this...
    Option Explicit
    
    Sub Populate_Chargebacks()
       Dim ws           As Worksheet
       Dim ws1          As Worksheet
       Dim LR           As Long
       Dim Rng          As Range
       Dim Rng1         As Range
       Dim cel          As Range
       Dim c            As Range
    
       Set ws = Sheets("Register")
       Set ws1 = Sheets("Chargebacks")
    
       Application.ScreenUpdating = False
       With ws
          LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                           SearchDirection:=xlPrevious).Row
          If Not .AutoFilterMode Then
             .Rows("1:1").AutoFilter
          End If
    
          .Range("A1:T" & LR).AutoFilter Field:=8, Criteria1:=Array( _
                                                              "NSF", "REFER", "CLOSE", "STOP"), Operator:=xlFilterValues
          .Range("A1:T" & LR).AutoFilter Field:=5, Criteria1:="6"
          .Range("A1:T" & LR).AutoFilter Field:=1, Criteria1:= _
                                         "<>Z99999", Operator:=xlAnd
    
          If Not .AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1 = 0 Then
             Set Rng = .Range(.Cells(2, "D"), .Cells(LR, "D")).SpecialCells(xlCellTypeVisible)
             Set Rng1 = ws1.Columns(1)
             For Each cel In Rng
                Set c = Rng1.Find(Format(cel.Value, "d-mmm-yy"), , xlValues, xlWhole, xlByRows, xlNext, False)
                If Not c Is Nothing Then
                   ws1.Cells(c.Row, "F").Value = ws1.Cells(c.Row, "F").Value + 1
                   ws1.Cells(c.Row, "G").Value = ws1.Cells(c.Row, "G").Value + cel.Offset(0, 2).Value
                End If
             Next cel
          Else: MsgBox "No records found"
          End If
          .AutoFilterMode = False
       End With
       Application.ScreenUpdating = True
    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. If a value is equal, populate the associate value
    By Sasti in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-02-2015, 03:59 PM
  2. Replies: 5
    Last Post: 04-19-2014, 10:09 PM
  3. [SOLVED] COUNTIFS function w/greater than or equal to, and less than or equal to time values
    By AliciaRenee in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-27-2014, 03:57 PM
  4. Scoresheet with Equal Ranks - need to identify equal placings separately
    By Caroleh in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-12-2014, 02:59 AM
  5. Replies: 3
    Last Post: 12-12-2012, 12:30 PM
  6. Replies: 0
    Last Post: 09-24-2010, 01:05 PM
  7. lower and upper case equal on spreadsheet but not equal in VB
    By don in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2005, 09: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