+ Reply to Thread
Results 1 to 2 of 2

Autoscroll through drop-down without hard coding the name of each value

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-28-2009
    Location
    Portland, Maine
    MS-Off Ver
    Excel 2003
    Posts
    102

    Autoscroll through drop-down without hard coding the name of each value

    I have reports that generated and sent to me each month. For now I need to separate the data that's in each report by the physical locations in column A. The list of sites is dynamic and changes from month to month.

    I'm looking for a way to select each unique value in column A, activate the range and save that range as a unique file without hardcode the actual value. I've done something similar in the past but I can't think of a simple way to do it in this exact situation.

    I have my initial skeleton/idea below. Any suggestions would be greatly appreciated

    Sub AutoscrollThroughPractices()
    
    '--------------------------------------------------------------------------------------------
    '   Set definitions...
    '--------------------------------------------------------------------------------------------
    Static iPracticeCount As Integer     'Count of unique practices
    Dim rStart As Range
    Dim rActive As Range
    Dim iMyCount As Integer
    Dim rPractice As Range
        Set rStart = Range("A1")
        Set rActive = Range(Range("A1").End(xlDown), Range("A1").End(xlToRight))
        iMyCount = CountUniqueValues(rPractice)
        Set rPractice = Range(Range("A2"), Range("A2").End(xlDown))
    
    
    '    On Error Resume Next
    '    '----------------------------------------------------------------------------------------
    '    '   Modify alerts
    '    '----------------------------------------------------------------------------------------
    '    With Application
    '    .DisplayAlerts = False
    '    .ScreenUpdating = False
            
            '------------------------------------------------------------------------------------
            '   Count of practices reached
            '   Reset the static variable and exit
            '------------------------------------------------------------------------------------
            If iMyCount = iPracticeCount Then
                    iPracticeCount = False
    
                    'reset object variables
                    Set rStart = Nothing
                    Set rActive = Nothing
                    Set rPractice = Nothing
             Exit Sub
        
            '------------------------------------------------------------------------------------
            '   Increment static variable by one until iMyCount  = Count of Practices reached
            '   If static variable is < iMyCount then add 1 to the static variable each time
            '   the macro is called
            '------------------------------------------------------------------------------------
            Else
                iPracticeCount = iPracticeCount + 1 'Add 1 tp static variable
                
                '--------------------------------------------------------------------------------
                '   Use something to increment through practice list
                '--------------------------------------------------------------------------------
    '            rActive.AutoFilter Field:=1, Criteria1:=iPracticeCount
    '           set a practice variable here
    '           Dim sPractice
    '               spractice = ???
                    
                    '----------------------------------------------------------------------------
                    '   Select filterered range and print to new file with name in practice
                    '----------------------------------------------------------------------------
                    rActive.Activate
    '                Create new file
    '                Name new file with sFileName = "1 - Done Not Done_" & sPractice
    '                save to dir:
                
                    '----------------------------------------------------------------------------
                    '   Re-call Autoscroll immediately
                    '----------------------------------------------------------------------------
                    Application.OnTime Now(), "AutoscrollThroughPractices"
    
            '------------------------------------------------------------------------------------
            '   End if check of count vs pcp count
            '------------------------------------------------------------------------------------
            End If
    
        'reset object variables
        Set rStart = Nothing
        Set rActive = Nothing
        Set rPractice = Nothing
    
    '    '----------------------------------------------------------------------------------------
    '    '   Modify alerts
    '    '----------------------------------------------------------------------------------------
    '    .DisplayAlerts = True
    '    .ScreenUpdating = True
    '    End With
    
    '--------------------------------------------------------------------------------------------
    '   End
    '--------------------------------------------------------------------------------------------
    End Sub

  2. #2
    Forum Contributor
    Join Date
    10-28-2009
    Location
    Portland, Maine
    MS-Off Ver
    Excel 2003
    Posts
    102

    Re: Autoscroll through drop-down without hard coding the name of each value

    I took a drive and the solution came to me. I did modify the above code and it works perfectly only scrolling through the unique values.

    process I took: Create a temporary list of unique values, named the list, used index fx and a static variable to increment through the list and gernate a unique file for each selection.

    Turned out to be pretty easy!!

+ Reply to 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