Results 1 to 15 of 15

Strange Results with custom filter and arrays

Threaded View

  1. #1
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Strange Results with custom filter and arrays

    Hi guys Im hoping someone could help me out a little, Ive been working on a huge custom filter which has 3 slight variations but they are all basically the same code

    Sub RemovePassedDate()
    Dim Lrow, i, j, k, c  As Long
    Dim str As String
    Dim vdata() As Variant
    Dim vResult() As Variant
    Dim Sheet As Worksheet
    Set Sheet = ActiveWorkbook.Sheets("Matches")
    Lrow = Sheet.Cells(Rows.Count, "B").End(xlUp).Row
    Application.ScreenUpdating = False
    vdata = Sheet.Range("A12:Z" & Lrow)
    ReDim vResult(UBound(vdata, 1), UBound(vdata, 2))
    For i = LBound(vdata, 1) To UBound(vdata, 1)
       If vdata(i, 1) > Now Then
          For c = 1 To UBound(vdata, 2)
             If c > 0 Then vResult(j, c - 1) = vdata(i, c)
          Next c
          j = j + 1
       End If
    Next i
    Sheet.Range("A12:Z" & Lrow).ClearContents
    Sheet.Range("A12:Z" & UBound(vResult, 1)) = vResult
    Application.ScreenUpdating = True
    End Sub

    I thought everything were working fine untill now when Ive tested it a little more.
    - Running the macro first time always produce the correct result.
    (this subs removes past dates based on values in col B)

    But If I am to run this sub for a 2nd time it removes more rows and outside of what I thought were the criteria . I'm not sure whats happening. I thought maybe the Lastrow var or something gets messed up but that's not the case.
    i also tried adding this at the end but didnt help

    Erase vdata
    Erase vResult
    Anyone know what might be the problem. Also Obviously I know its necessary to run this macro more then once but I would Like to run a quite similar macro after this one but its not working as I would expect ??

    any help would be much appreciated..

    frederik
    Last edited by colddeck84; 09-28-2017 at 09:02 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 8
    Last Post: 06-07-2016, 11:28 AM
  2. strange results when using formula
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-27-2016, 06:53 AM
  3. Need help creating custom sheets based on auto filter results
    By trow in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-28-2012, 04:10 PM
  4. Replies: 3
    Last Post: 03-31-2010, 11:47 AM
  5. Custom Bar Chart....strange question
    By Trick in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 11-08-2006, 09:55 AM
  6. Strange results...
    By Jim May in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-24-2006, 05:30 PM
  7. Strange IF results
    By MWE in forum Excel General
    Replies: 0
    Last Post: 03-25-2005, 08:14 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