+ Reply to Thread
Results 1 to 6 of 6

Thread: Excel VBA filtering assistance

  1. #1
    Registered User
    Join Date
    01-23-2012
    Location
    Midlands, England
    MS-Off Ver
    Excel 2003
    Posts
    4

    Excel VBA filtering assistance

    Hello,

    I'm new to the forum and pretty new to excel VBA. I have a large spreadsheet and would like to filter it.

    The spreadsheet has many columns, although only one I want to use for sorting. It is an integer value (Availability) and every time it changes compared to the previous row i'd like to record the change (i.e. copy the whole row with the new Availability figure and the previous row with the old Availability figure into a new spreadsheet).

    I can run an autofilter, but now I don't know if there is a way I can access the row index of the filtered results easily in VBA? If so, that would make things easier.. Or any other suggestions of alternative approaches?

    Would be very grateful for any assistance.

    Many thanks,

    tonypanda
    Last edited by tonypanda; 01-26-2012 at 03:46 AM. Reason: solved

  2. #2
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,396

    Re: Excel VBA filtering assistance

    It would be good if you attach a sample file. Would only the availability column change or would other columns change?
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    01-23-2012
    Location
    Midlands, England
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Excel VBA filtering assistance

    Ok, thanks. Example attached of what I'd like to do. example.xls

  4. #4
    Registered User
    Join Date
    01-23-2012
    Location
    Midlands, England
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Excel VBA filtering assistance

    Ok, thanks. Example attached of what I'd like to do. Attachment 137682 hope this makes it clear!

    All the other columns will be different, but I do need to retain that information - for example the date and time when the availability changed.
    Last edited by tonypanda; 01-24-2012 at 04:14 AM.

  5. #5
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,396

    Re: Excel VBA filtering assistance

    Hey Tonypanda,

    Use this code -
    Option Explicit
    Dim lrow As Long
    Dim i As Long
    
    Sub compare_rows()
    
    lrow = Worksheets(1).Range("A" & Rows.Count).End(xlUp).Row
    Worksheets(1).Rows("1:1").Copy Worksheets(2).Range("A1")
    For i = 2 To lrow - 1
        If Worksheets(1).Range("C" & i).Value <> Worksheets(1).Range("C" & i + 1).Value Then
            Worksheets(1).Rows(i & ":" & i + 1).Copy Worksheets(2).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
        End If
    Next i
    End Sub
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  6. #6
    Registered User
    Join Date
    01-23-2012
    Location
    Midlands, England
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Excel VBA filtering assistance

    Thanks a lot - works a treat!

+ 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