+ Reply to Thread
Results 1 to 5 of 5

Thread: input box dosent quite work

  1. #1
    Registered User
    Join Date
    07-14-2011
    Location
    Argentina
    MS-Off Ver
    Excel 2003
    Posts
    13

    input box dosent quite work

    Hello there, im new to macros got a macro an im trying to do a filter with a inputbox that deletes the rows if it dosent found the word or if the cell is blank in the column, heres the code:

    Sub filtro()
        Dim lr As Long
        Dim box    
    
        box = InputBox("Filtrar:")
        lr = Range("D" & Rows.Count).End(xlUp).Row
        
        With Range("D1:D" & lr)
            .AutoFilter Field:=1, Criteria1:="<>box"
            .Offset(1).EntireRow.Delete
            .AutoFilter
        End With
    
    End Sub
    it deletes everything :P i just whant to delete the words of the inputbox and rows containing blank cells

    well thats all thanks.
    Last edited by babar48; 07-14-2011 at 10:00 PM. Reason: poor english

  2. #2
    Valued Forum Contributor
    Join Date
    11-11-2008
    Location
    Euro
    MS-Off Ver
    2003, 2007
    Posts
    384

    Re: input box dosent quite work

    the result of Inputbox method depends on the TYPE of data:

    If the number plz, change to
     box = InputBox("Filtrar:",Type:=1)
    if the text (string)
     box = InputBox("Filtrar:", Type:=2)
    if the range
     box = InputBox("Filtrar:", Type:=8)
    AND also change
    .AutoFilter Field:=1, Criteria1:="<>box"
    to
    .AutoFilter Field:=1, Criteria1:="<>" & box
    Last edited by tigertiger; 07-14-2011 at 07:28 PM.

  3. #3
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: input box dosent quite work

    Hi babar48, you were close. Notice the "<>" & box in
    Sub filtro()
        Dim lr As Long
        Dim box As String
        box = InputBox("Filtrar en Categorķa:")
        lr = Range("D" & Rows.Count).End(xlUp).Row
          With Range("D1:D" & lr)
            .AutoFilter Field:=1, Criteria1:="<>" & box
            .EntireRow.Delete
            .AutoFilter
        End With
    End Sub
    If it remains in quotes then the criteria will always be box and that's it.
    Please leave a message after the beep!

  4. #4
    Registered User
    Join Date
    07-14-2011
    Location
    Argentina
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: input box dosent quite work

    thanks guys, problem solved :D

  5. #5
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: input box dosent quite work

    If your problem has been solved please mark your thread as solved. Also, if you feel that members of this forum have helped you out then don't be bashful and tap their scales (located at the top right of each post).


    Kind Regards:
    Please leave a message after the beep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0