+ Reply to Thread
Results 1 to 5 of 5

Macro filtering, remove name99, keep name1 and all data in your row, not working macro

  1. #1
    Registered User
    Join Date
    03-08-2017
    Location
    Germany
    MS-Off Ver
    2010
    Posts
    2

    Macro filtering, remove name99, keep name1 and all data in your row, not working macro

    Hello people,
    got this macro for filtering but it is not working as it should.
    I have a excel list with 5 columns. In A we have file names. All of them contain jpg, png, gif, pdn, sometimes filename jpg pdn, or filename jpg gif pdn. In column 2,3,4... I have additional information.
    I want to remove ALL pda and gif. BONUS: It would be really nice, if I could keep all files which pdn. E.g. delete all rows which contain pdn but if it has jpg, keep it. this is only bonus and has no priority.

    Here is a example, because often it is difficult to understand me :| http://imgur.com/a/5ys9u

    Here is the macro which is not working, because it only keeping column A, also the bonus mention above is not a option.

    PHP Code: 
    Option Explicit

    Public Sub FilterColumn()
        
    Dim InputWS As WorksheetSet InputWS ActiveSheet
        Worksheets
    .Add After:=Worksheets(Worksheets.Count)
        
    Dim OutputWS As WorksheetSet OutputWS Worksheets(Worksheets.Count)
        
    Dim SearchTerms As VariantSearchTerms = Array("jpg""png")
        
    Dim ExcludeTerms As VariantExcludeTerms = Array("gif""pdn")
        
    Dim Counter As LongRowCounter As LongTermFound As Boolean
        Call LudicrousMode
    (True)
        For 
    RowCounter 1 To GetLastRow(InputWS1)
            For 
    Counter 0 To UBound(SearchTerms)
                If 
    InStr(1InputWS.Cells(RowCounter1).ValueSearchTerms(Counter)) > 0 Then TermFound True
            Next Counter
            
    For Counter 0 To UBound(ExcludeTerms)
                If 
    InStr(1InputWS.Cells(RowCounter1).ValueExcludeTerms(Counter)) > 0 Then TermFound False
            Next Counter
            
    If TermFound True Then
                
    For Counter 1 To 4
                    OutputWS
    .Cells(GetLastRow(OutputWSCounter) + 11).Value InputWS.Cells(RowCounterCounter).Value
                Next Counter
                TermFound 
    False
            End 
    If
        
    Next RowCounter
        Call LudicrousMode
    (False)
        
    Set OutputWS Nothing
        Set InputWS 
    Nothing
    End Sub

    Public Sub LudicrousMode(ByVal Toggle As Boolean)
        
    Application.ScreenUpdating Not Toggle
        Application
    .EnableEvents Not Toggle
        Application
    .DisplayAlerts Not Toggle
        Application
    .Calculation IIf(TogglexlCalculationManualxlCalculationAutomatic)
    End Sub

    Public Function GetLastRow(ByVal TargetWorksheet As WorksheetByVal ColumnNo As Long) As Long
        GetLastRow 
    TargetWorksheet.Cells(TargetWorksheet.Rows.CountChr(64 ColumnNo)).End(xlUp).Row
    End 
    Function 
    Would be awesome if you could help me out
    Best wishes,
    Gusop

  2. #2
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: Macro filtering, remove name99, keep name1 and all data in your row, not working macro

    This will remove all rows with gif or pdn file extensions and keep everything else.
    Please Login or Register  to view this content.
    MatrixMan.
    --------------------------------------
    If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
    If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.

  3. #3
    Registered User
    Join Date
    03-08-2017
    Location
    Germany
    MS-Off Ver
    2010
    Posts
    2

    Re: Macro filtering, remove name99, keep name1 and all data in your row, not working macro

    I get a error message:

    Illegal use of the keyword Me

    I translated the error message from german to english with google. I use excel 2010.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Macro filtering, remove name99, keep name1 and all data in your row, not working macro

    Try
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: Macro filtering, remove name99, keep name1 and all data in your row, not working macro

    Yep - that will work - thanks jindon. @Gusop - the invalid use of me is because I suspect you put the code in a module or the workbook object and not the sheet object.

+ 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. Macro for filtering data
    By ldurham in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-01-2016, 09:19 AM
  2. [SOLVED] Vba to remove wordart. Recording not working in macro.
    By thecdnmole in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-28-2014, 02:18 PM
  3. Macro for filtering table via textbox not working with numbers
    By adrianrff in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-05-2014, 11:26 AM
  4. Help about macro and filtering data
    By bitaz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-04-2011, 02:14 AM
  5. Search filtering macro stopped working
    By James_B in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2010, 11:04 AM
  6. [SOLVED] Remove Subtotal In Macro Not Working
    By Jerry Cropanese in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 06-27-2005, 01:05 AM
  7. filtering data with a macro
    By Jack in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2005, 12: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