Results 1 to 5 of 5

Excel 2007 : Auto select and copy rows containing a cell with a specific value

Threaded View

  1. #3
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Auto select and copy rows containing a cell with a specific value

    Was working on this when Dave posted - oh well, can't let effort go to waste.
    The attached automates Advanced Filter and population of the validation list and uses the worksheet activate and change events.

    Option Explicit
    
    Private Sub Worksheet_Activate()
        Dim lastrow As Long, rng1 As Range
        Dim BrandList As String, bottomrow As Long, rngVal_list As Range
        
        lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
        bottomrow = Me.Cells(Rows.Count, 1).End(xlUp).Row
        Set rng1 = Sheet1.Range("B3:B" & lastrow)
        
        Application.ScreenUpdating = False
        
        With Me
        
            .Range("A7:A" & Rows.Count).End(xlUp).ClearContents
            
            rng1.AdvancedFilter xlFilterCopy, , .Range("A7"), True
            
            Set rngVal_list = .Range("A8:A" & bottomrow)
            
            ThisWorkbook.Names.Add Name:="BrandList", RefersTo:=rngVal_list
            
            .Range("C4").Validation.Delete
            
            .Range("C4").Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=BrandList"
        End With
        
        Set rng1 = Nothing
        
        Application.ScreenUpdating = True
        
    End Sub
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        Dim lastrow As Long
        
        lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
    
        Set rng2 = Sheet1.Range("A3:K" & lastrow)
        
        Application.ScreenUpdating = False
        
        On Error Resume Next
    
        With Me
            If Not Intersect(ActiveCell, .Range("C4")) Is Nothing Then
                .Range("B7").CurrentRegion.Offset(, 1).ClearContents
                rng2.AdvancedFilter xlFilterCopy, .Range("B1:B2"), .Range("B7")
            End If
        End With
        
        Application.ScreenUpdating = False
        
        Set rng2 = Nothing
    End Sub
    Attached Files Attached Files
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

Thread Information

Users Browsing this Thread

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

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