Results 1 to 4 of 4

If then Statements & checked Boxes

Threaded View

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

    If then Statements & checked Boxes

    Hi Guys , great forum you have here ...

    Obligitory N00b post about how I am new to VB & am in need of assistance ...


    I'm trying to create a macro that says if optionbutton1 & optionbutton2 are checeked then create a graph with this (xyz:xyz)range ... else if optionbutton1 & 3 are checked then create a graph with (abc:abc) range .... etc etc


    so the good is that it does create the graph with the correct range(s) ...

    the problem is that it does not just make the ones with the checked boxes with appropriate variable , it makes every combination of graph & I only want it to select the range that correspond with the checked boxes

    so here is the code I have , hopefully its obvious what I have done wrong



    Private Sub Graph_Click()
    
    
    
    If optionbutton1.Value = True And optionbutton3.Value = True Then range("C20:C105").Select
        range("C20:C105,E20:E105").Select
        range("E20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$C$20:$C$105,Calculations!$E$20:$E$105")
    
            
            
    If optionbutton1.Value = True And optionbutton3.Value = True And optionbutton4.Value = True Then range("C20:C105").Select
       
        range("C20:C105,E20:E105").Select
        range("E20").Activate
       
        range("C20:C105,E20:E105,F20:F105").Select
        range("F20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$C$20:$C$105,Calculations!$E$20:$E$105,Calculations!$F$20:$F$105" _
            )
    
            
            
            
    If optionbutton1.Value = True And optionbutton3.Value = True And optionbutton4.Value = True And Optionbutton5.Value = True Then range("C20:C120").Select
        range("C20:C120,E20:E120").Select
        range("E20").Activate
        range("C20:C120,E20:E120,F20:F120").Select
        range("F20").Activate
        range("C20:C120,E20:E120,F20:F120,G20:G120").Select
        range("G20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$C$20:$C$120,Calculations!$E$20:$E$120,Calculations!$F$20:$F$120,Calculations!$G$20:$G$120" _
            )
    
    
    
    If optionbutton1.Value = True And optionbutton4.Value = True Then range("C20:C105").Select
        range("C20:C105,F20:F105").Select
        range("F20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$C$20:$C$105,Calculations!$F$20:$F$105")
    
    
    If optionbutton1.Value = True And Optionbutton5.Value = True Then range("C20:C121").Select
        range("C20:C121,G20:G121").Select
        range("G20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$C$20:$C$121,Calculations!$G$20:$G$121")
    
    If optionbutton2.Value = True And optionbutton3.Value = True Then range("D20:D105").Select
        range("D20:D105,E20:E105").Select
        range("E20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$D$20:$D$105,Calculations!$E$20:$E$105")
    
    
    If optionbutton2.Value = True And optionbutton4.Value = True Then range("D20:D105").Select
        range("D20:D105,F20:F105").Select
        range("F20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$D$20:$D$105,Calculations!$F$20:$F$105")
    
            
    If optionbutton2.Value = True And Optionbutton5.Value = True Then range("D20:D121").Select
        range("D20:D121,G20:G121").Select
        range("G20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$D$20:$D$121,Calculations!$G$20:$G$121")
    
    
    If optionbutton2.Value = True And optionbutton3.Value = True And optionbutton4.Value = True Then range("D20:D105").Select
        range("D20:D105,E20:E105").Select
        range("E20").Activate
        range("D20:D105,E20:E105,F20:F105").Select
        range("F20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$D$20:$D$105,Calculations!$E$20:$E$105,Calculations!$F$20:$F$105" _
            )
    
    
    If optionbutton2.Value = True And optionbutton3.Value = True And optionbutton4.Value = True And Optionbutton5.Value = True Then range("D20:D121").Select
        
        range("D20:D121,E20:E121").Select
        range("E20").Activate
        range("D20:D121,E20:E121,F20:F121").Select
        range("F20").Activate
        range("D20:D121,E20:E121,F20:F121,G20:G121").Select
        range("G20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$D$20:$D$121,Calculations!$E$20:$E$121,Calculations!$F$20:$F$121,Calculations!$G$20:$G$121" _
            )
    
    
    If optionbutton3.Value = True And optionbutton4.Value = True Then range("E20:E121").Select
        range("E20:E121,F20:F121").Select
        range("F20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$E$20:$E$121,Calculations!$F$20:$F$121")
    
    If optionbutton3.Value = True And optionbutton4.Value = True And Optionbutton5.Value = True Then range("E20:E121").Select
        range("E20:E121,F20:F121").Select
        range("F20").Activate
        range("E20:E121,F20:F121,G20:G121").Select
        range("G20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$E$20:$E$121,Calculations!$F$20:$F$121,Calculations!$G$20:$G$121" _
            )
    
    
    If optionbutton3.Value = True And Optionbutton5.Value = True Then range("E20:E121").Select
        range("E20:E121,G20:G121").Select
        range("G20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$E$20:$E$121,Calculations!$G$20:$G$121")
    
    
    
    If optionbutton4.Value = True And Optionbutton5.Value = True Then range("F20:F121").Select
        range("F20:F121,G20:G121").Select
        range("G20").Activate
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=range( _
            "Calculations!$F$20:$F$121,Calculations!$G$20:$G$121")
           
    
    
    
    End Sub
    Last edited by Leith Ross; 02-14-2012 at 04:44 PM. Reason: Changed Quote Tags to Code Tags

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