+ Reply to Thread
Results 1 to 15 of 15

Strange Results with custom filter and arrays

  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

    Please Login or Register  to view this content.

    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

    Please Login or Register  to view this content.
    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.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Strange Results with custom filter and arrays

    If vdata(i, 1) > Now Then
    Checks column A, but B.
    It would be easier to see why the code does not produce the desired result with a sample. Please attach a sample.
    If you are merely checking for a condition, you could probably use a filter than a loop.

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

    Re: Strange Results with custom filter and arrays

    Hi thanks for your reply and sorry for my late response, im not sure there will be possible with a built in filter , (except for this sample) as I have several custom Filters using the same loop, I'll attach a workbook sample ,

    (but it must be tested within 30 min or everything will be removed)

    frederik
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Strange Results with custom filter and arrays

    I do not see any error. Mind you the function "Now" is volatile.

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

    Re: Strange Results with custom filter and arrays

    did you press twice ? because its on the second press the strangeness is happening

    edit: I also have a filter that removes based on country/league (but almost same code) and it also produce exactly the same results , Correct on first press but then it removes more on 2nd press
    Last edited by colddeck84; 09-28-2017 at 02:55 PM.

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

    Re: Strange Results with custom filter and arrays

    Here is the 2nd code, I've updated the sample with all corresponding data
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Strange Results with custom filter and arrays

    You are right! The code was not right.
    Try

    Please Login or Register  to view this content.

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

    Re: Strange Results with custom filter and arrays

    Thanks for your help and good eye I see that you made several changes..
    do you see what that is incorrect with the 2nd code also ? what was producing these strange results ?

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Strange Results with custom filter and arrays

    I do not how I did notice the flow in the code when I first tested it.
    It has many flows. You are right to see stange result.

    Look at this

    Please Login or Register  to view this content.
    As the code loops through columns for the first time the first row (j) is 0

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

    Re: Strange Results with custom filter and arrays

    so that's whats producing the strange behavior? thanks for the help. Im totally busted I've painted my house today so I'm gonna test this more out tomorrow with a fresh head , Many thanks for your input and help

    frederik

    Edit: sorry I was not able to give you any more rep as I gave you earlier

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Strange Results with custom filter and arrays

    There are few, but the main one is

    The j value is calculated correctly but, when you dump the data back to excel, see what you get

    Sheet.Range("A12:Z" & UBound(vResult, 1)) = vResult

    and probably this line too

    ReDim vResult(UBound(vdata, 1), UBound(vdata, 2))
    I have never done output starting from 0, as oppose to 1.

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

    Re: Strange Results with custom filter and arrays

    Oh this became more complicated that I can comprehend at this point , also I used almost a full day compiling this as im no professional coder and this is some sort of extra hobby project ..

    I had some problems with this code and you are right originally when I tried to dump it back into the sheet everything got offset by 1 , (column and row) so my workaround was this:

    Please Login or Register  to view this content.
    I guess more was disturbed giving me incorrect values., I guess if I edit you version everything will work as expected ?

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Strange Results with custom filter and arrays

    Yes, my version will work well. Test it tomorrow and post it back if you have any issue.

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

    Re: Strange Results with custom filter and arrays

    yup ill report back tomorrow.. thanks alot for your time and help .. you have been great.

    frederik

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

    Re: Strange Results with custom filter and arrays

    Good morning. I tested this and it works great Im gonna study this a little more just to see exactly everything that I did incorrect.

    - And you are a real life saver. Im working on a huge custom filter were I can remove countries / Leagues from this list,
    running your latest edit now gave no errors. And also I can Run all three filters in a row without any problems

    thanks alot

    frederik

+ 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. 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. [SOLVED] 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