Consulting

Results 1 to 6 of 6

Thread: Solved: Find All function works Intermittantly

  1. #1
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location

    Solved: Find All function works Intermittantly

    I knew i would be back with this one from a previous post
    I am using Chip Pearsons routine to find all occurences on a sheet

    When i open up the form and go to that tab and run it it does not find anything at all, if i go back and clear Col T on the MainDB sheet then reinput "I" in that column then it works ok, But........... as soon as i close the WB down then reopen it go to that tab and run the routine it comes up with nothing again!!!!!!

    Does anybody have any idea why it is doing this or am i missing something?
    Have tried all the obvious (Trim) etc but nothing seems to work
    Enclosed a sample workbook but this works every time??

    Rob
    Attached Files Attached Files

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I don't see a problem. If you run it an that sheet is not the active one, then nothing is found.

  3. #3
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Hi Kenneth
    Thanks for looking
    I have added .activate to the routine and now it works all the time

    I always thought by using set ws=worksheets("Sheet1") along with
    With & End With, automatically activates the sheet?

    Rob

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    That's a lot of code to perform a simple action:

    [vba]
    Sub snb()
    With Sheets("MainDB").Cells(1).CurrentRegion.Columns(20)
    .AutoFilter 1, "I"
    MsgBox .Offset(1).SpecialCells(12).Address
    .AutoFilter
    End With
    End Sub

    [/vba]

    PS. Although you used With... End with , you forgot to add dots before the Range.
    Read some more on With ... End With in the VBA helpfiles.

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    As snb showed, Activate and Select are usually not needed. This usually makes your macros faster.

  6. #6
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Kenneth & snb

    Thanks for help both most appreciated

    Rob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •