Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

i have a sheet with some sets of da

Status
Not open for further replies.

VBAva

Programmer
Jul 29, 2003
87
IE
i have a sheet with some sets of data, and i want to plot some of them.
the sheets columns are like this
Time X Y X RSS
at different times i want to plot different columns( X Y or Y Z RSS etc) but always using the time along the X axis.
i have created a form with a check box for each column. there are two different types of data- Scaled and Filtered. this plotting Sub should work for both.
the check box values are stored in ScaleX, FilterX etc.
NameOfSheet comes from a text box.

I have been looking at the code and it seems to be ok, but strange things are happening. Columns are being plotted when i did not check the box, like this
what should be plotted what is plotted
X Z X
Y Z Y
Z Z Z
RSS RSS RSS
X Y Z X Y
X Y Z Z X Y Z
Z RSS RSS Z RSS
X Y Z RSS RSS X Y Z RSS
Y RSS RSS Y RSS

I dont konw why this is happening.
Something that may be realevent is that in the form, the check boxes for X Y and Z are in a row, and RSS is below them. it seems to be that if anything from the top row is selected, that an extra Z is added in, or once the RSS is selected that an extra RSS series is added.

here is the code for it, i have not been using VBA long so if you spot any mistakes please let me know
thank you in advance


Code:
Public Sub CalcGraph()

    Application.ScreenUpdating = False
    
    Range("A14").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.name = "TimeRange"

    Range("B14").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.name = "XSelection"

    Range("C14").Activate
    Range(Selection, Selection.End(xlDown)).Select
    Selection.name = "YSelection"

    Range("D14").Activate
    Range(Selection, Selection.End(xlDown)).Select
    Selection.name = "ZSelection"

    If ScaleRSS = True Or FilterRSS = True Then
        Range("E14").Activate
        Range(Selection, Selection.End(xlDown)).Select
        Selection.name = "RSSSelection"
    End If

    Charts.Add
    ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
    ActiveChart.Location Where:=xlLocationAsNewSheet, name:=NameOfSheet
    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "Data"
        .Axes(xlCategory, xlPrimary).HasTitle = True
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time"
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Amplitude"
        .HasAxis(xlCategory, xlPrimary) = True
        .HasAxis(xlValue, xlPrimary) = True
    End With

    With ActiveChart.Axes(xlValue)
        .Crosses = xlCustom
        .CrossesAt = ActiveChart.Axes(xlValue).MinimumScale
    End With
    
    If ScaleX = True Or FilterX = True Then
        ActiveChart.SeriesCollection.Add Source:=Sheets("New_Data").Range("XSelection")
    End If
    If ScaleY = True Or FilterY = True Then
        ActiveChart.SeriesCollection.Add Source:=Sheets("New_Data").Range("YSelection")
    End If
    If ScaleZ = True Or FilterZ = True Then
        ActiveChart.SeriesCollection.Add Source:=Sheets("New_Data").Range("ZSelection")
    End If
    If ScaleRSS = True Or FilterRSS = True Then
        ActiveChart.SeriesCollection.Add Source:=Sheets("New_Data").Range("RSSSelection")
    End If
    
    ActiveChart.SeriesCollection(1).XValues = Range("TimeRange")
    Application.ScreenUpdating = True
End Sub
 
Hi There,

It looks like you will return "strange" data at this point.

Range("C14").Activate
Range(Selection, Selection.End(xlDown)).Select
Selection.name = "YSelection"

You are activating a cell and then trying to reference it by using "selection" - this will not work as the vba code will use the last Selected cell as opposed to the last active cell.

I am having muchos fun at the mo creating an interactive graph so any "graph" related queries let me know and i'll be happy to help.


Let me know how you get on......

John

 
Thanks John for that selection thing,
but it has not effected the strangness.

i still keep getting RSS or Z series when i dont want them!

weird or what!

i even took out the
If ScaleZ = True Or FilterZ = True Then
ActiveChart.SeriesCollection.Add Source:=Sheets("New_Data").Range("ZSelection")
End If

bit but it still plots the data
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top