+ Reply to Thread
Results 1 to 2 of 2

Dynamic Range Help

Hybrid View

  1. #1
    Registered User
    Join Date
    02-10-2012
    Location
    ON
    MS-Off Ver
    Excel 2010
    Posts
    12

    Dynamic Range Help

    I'm trying to make a dynamic range based on checked boxes that spans columns c e f g h


    ElseIf optionbutton1.value = True And optionbutton3.value = True And optionbutton4.value = True And Optionbutton5.value = True And optionbutton6.value = True Then
        Dim DynamicRange As Range
         
         ActiveSheet.Select
       Range("C20,E20,F20,G20,H20").Select
        Range("H20").Activate
        Set DynamicRange = Range(Selection, Selection.End(xlDown))
        DynamicRange.Select
            
    
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=DynamicRange

    but for some reason it will only select the C column and not the rest (e f g h )

    what am I doing wrong here ?

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

    Re: Dynamic Range Help

    Hi c7015, try adapting the following code into your procedure. Let me know if you need more assistance.
    Sub c7015()
    
        Dim Rng1 As Range, Rng2 As Range
        Dim Ws As Worksheet
        Dim DynamicRange As Range
        
        Set Ws = Worksheets("Sheet1")
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        '''Set Rng1 & Rng2's locations and then add them via Union  '''
        '''to the DynamicRange variable.                            '''
        Set Rng1 = Ws.Range(Ws.Cells(20, 3), Ws.Cells(Ws.Rows.Count, 3).End(xlUp))
        Set Rng2 = Ws.Range(Ws.Cells(20, 5), Ws.Cells(Ws.Rows.Count, 8).End(xlUp))
        Set DynamicRange = Union(Rng1, Rng2)
        
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=DynamicRange
        
    End Sub
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

+ 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