+ Reply to Thread
Results 1 to 5 of 5

Excel Macro filtering only 1st item out of multiple items from the source data

Hybrid View

  1. #1
    Registered User
    Join Date
    09-27-2015
    Location
    India
    MS-Off Ver
    MS Office 2013
    Posts
    2

    Excel Macro filtering only 1st item out of multiple items from the source data

    Hi,

    Can someone please help me with a problem i am facing in excel wherein when i filter my data using the macro, only the first item is being filtered. i have attached the sheet, can someone please advise what coding in the macro is wrong. i have the button in sheet 1, when i press it, it asks for the fund number. i enter a fund number and only the first item from the source data is selected. my data is in sheet 2 and i obtain the result in sheet 3. Please use fund 2618 as example as it has multiple line items in the source data
    Attached Files Attached Files

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Excel Macro filtering only 1st item out of multiple items from the source data

    You are using find and looping. When you use find and don't combine that with findnext it will just keep finding the first instance of what you are looking for. In the visual basic editor there is a help search box. Type in range.findnext and you will find some good sample code to work with. You might also consider autofilter.

    Autofilter.

  3. #3
    Registered User
    Join Date
    09-27-2015
    Location
    India
    MS-Off Ver
    MS Office 2013
    Posts
    2

    Re: Excel Macro filtering only 1st item out of multiple items from the source data

    hi,
    can you please advise me on how to correct my code by using .findnext as i am not that good with vba codes and copied the current coding from somewhere
    thanks in advance

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel Macro filtering only 1st item out of multiple items from the source data

    Hi zipperzipped1204

    Welcome to the Forum!!!

    As skywriter suggested, Auto Filter would be the tool of choice for this exercise. Need to pick up my Grandson at the School Bus Stop in a few. If you've not been helped when I get back I'll look at it with you.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel Macro filtering only 1st item out of multiple items from the source data

    Hi zipperzipped1204

    Try this...
    Option Explicit
    
    Sub Filter1()
       Dim ws           As Worksheet
       Dim Rng          As Range
       Dim LR           As Long
       Dim x            As Long
       Dim Accno        As Long
    
       On Error Resume Next
       Application.DisplayAlerts = False
    
       Accno = Application.InputBox("Enter Account number", Type:=1)
       Application.DisplayAlerts = True
    
       On Error GoTo 0
       If Accno = 0 Then
          Exit Sub
       Else
          Set ws = Sheets("Sheet2")
          With ws
             LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                              SearchDirection:=xlPrevious).Row
             ActiveSheet.Range("A1:E" & LR).AutoFilter Field:=1, Criteria1:=Accno
    
             Set Rng = .AutoFilter.Range
             x = Rng.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1
             If x >= 1 Then
                .Range(.Cells(2, "A"), .Cells(LR, "E")).SpecialCells(xlCellTypeVisible).Copy _
                      Destination:=Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1)
             End If
             .AutoFilterMode = False
          End With
       End If
    End Sub

+ 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. [SOLVED]How to VLookup multiple items when the source has multiple identical numbers
    By jackson_hollon in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-17-2014, 12:56 AM
  2. Replies: 8
    Last Post: 09-24-2013, 05:52 AM
  3. [SOLVED] Custom filtering problem for multiple item
    By ryan4646 in forum Excel General
    Replies: 1
    Last Post: 08-28-2013, 03:22 AM
  4. Macro for selecting a single item while filtering the data in Pivot Table
    By Syed964 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-13-2013, 01:28 PM
  5. Auto Filtering Macro that Filters for more than one item
    By murph8868 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-05-2013, 03:18 PM
  6. Replies: 0
    Last Post: 09-25-2012, 11:34 AM
  7. Excel Data Validation - Select Multiple Items - Need to Apply Macro to Multiple Rows
    By kristynroll in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2012, 07:44 PM

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.6.0 RC 1