Consulting

Results 1 to 12 of 12

Thread: filter - hide active cell content

  1. #1

    filter - hide active cell content

    hi all,
    pls. how can i change this code, that it filtering the same value as i see (format) not, what is in cell?

    now its Works this way:
    if i have in column date „21.2.09“. I want hide this date in column.
    I use autofilter but i use value 21.2.2009 not 21.02.09 and this doesnt filter nothing.
    I need it change this way, that if i use my code it will short year 09 insted 2009 because with 09 it works. If i manualy use custome filter and write 21.2.09 it works.

    How can i fix it?

    Sub filter_NEOBSAHUJE_AktivBunka()
     
        Dim col, val, ctr As Long
        col = ActiveCell.Column
        val = ActiveCell.Value
        ctr = WorksheetFunction.CountBlank(Columns(col))
            val = ActiveCell.Value
        Set FiltRng = ActiveSheet.AutoFilter.Range
        col = Selection.Column - FiltRng(1).Column + 1 '<++++++++++++
        If FiltRng.Columns.Count = 1 And col = 0 Then col = 1
        FiltRng.AutoFilter Field:=col, Criteria1:=("<>" & val)
    End Sub
    Last edited by danovkos; 08-14-2009 at 01:07 AM.

  2. #2
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    try that:

    [VBA]
    Dim Temp As String, val As String

    If Len(val) > 8 Then
    Temp = Left(val, Len(val) - 4) & Right(val, 2)
    val = Temp
    End If
    [/VBA]

  3. #3
    No it doesnt works?
    It does, what i wanted(change year 2009 to 09) but the results doesnt changed.

    But interesting is, that when i open filter, part Custome filter and send enter it works and it filtering the date. Why?

  4. #4
    and now i figured out, that this i can not use because i use this code for filtering all my data. e.g. filtering names and so...
    and it will not works for everything

  5. #5
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    There was always some problems with passing variable with date to the filter.

  6. #6
    is there any way to fix it?

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post a copy of the actual data to be filtered.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    here is my fake table (red column)

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    How about getting rid of the dates!
    [VBA]
    Sub Macro2()
    col = ActiveCell.Column
    Set filtrng = Range("A2:J1622")
    ActiveCell.EntireColumn.Cells.NumberFormat = "General"
    filtrng.AutoFilter Field:=6, Criteria1:="<>" & CLng(ActiveCell)
    ActiveCell.EntireColumn.Cells.NumberFormat = "mmmm yyyy"
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    I don't think there is a real way to fix it as the problem is related with how the Excel is localizing the date format.

  11. #11
    Quote Originally Posted by mdmackillop
    How about getting rid of the dates!
    [vba]
    Sub Macro2()
    col = ActiveCell.Column
    Set filtrng = Range("A2:J1622")
    ActiveCell.EntireColumn.Cells.NumberFormat = "General"
    filtrng.AutoFilter Field:=6, Criteria1:="<>" & CLng(ActiveCell)
    ActiveCell.EntireColumn.Cells.NumberFormat = "mmmm yyyy"
    End Sub
    [/vba]
    no it doesnt work
    here in atach are my regional settings...if it helps

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    No attachment
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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