RawlinsCross
Active Member
- Joined
- Sep 9, 2016
- Messages
- 437
Hi there. I have two rows of data (x=time and y=diameter). There are a total of 30 rows of data and oftentimes there may be 2 or more identical values of the diameter for 2 or more days. I want to scan through the diameter data and output only the non-sequential-identical numbers.
The code works in part (i.e. it removes sequentially identical points) but it doesn't retain the correct value of the date in the x column. What happens is that it reverts the date starting from Jan-00. So basically it's turning the X-axis date values into 1...2...3...4...5....#number of unique non-sequential# values instead of the actual dates. Here is the code:
The code works in part (i.e. it removes sequentially identical points) but it doesn't retain the correct value of the date in the x column. What happens is that it reverts the date starting from Jan-00. So basically it's turning the X-axis date values into 1...2...3...4...5....#number of unique non-sequential# values instead of the actual dates. Here is the code:
Code:
Private Sub UserForm_Initialize()
Dim ChartData As Range
Dim ChartXData As Range
Dim MyChart As Chart
Dim lDataIndex As Long
Dim lDataIndex2 As Long
Dim ChartName As String
Dim aryX() As Variant
Dim aryY() As Variant
Dim aryX2() As Variant
Dim aryY2() As Variant
Dim rngcell As Range
Dim lDataCount As Long
Application.ScreenUpdating = False
Worksheets("Dashboard").Range("H4").Value = ActiveWindow.Zoom
ActiveWindow.Zoom = 85
'Define Source Ranges
Set ChartData = Worksheets("212-LT").Range("P9:P38")
Set ChartXData = Worksheets("212-LT").Range("B9:B38")
'Copy data to arrays
For Each rngcell In ChartData
lDataIndex = lDataIndex + 1
ReDim Preserve aryY(1 To lDataIndex)
aryY(lDataIndex) = rngcell.Value
Next
lDataIndex = 0
For Each rngcell In ChartXData
lDataIndex = lDataIndex + 1
ReDim Preserve aryX(1 To lDataIndex)
aryX(lDataIndex) = rngcell.Value
Next
lDataIndex = lDataIndex
'Remove sequential duplicates
ReDim Preserve aryX2(1 To lDataIndex)
ReDim Preserve aryY2(1 To lDataIndex)
aryX2(1) = aryX(1)
aryY2(1) = aryY(1)
lDataIndex2 = 1
For lDataIndex = 2 To lDataIndex
If aryY(lDataIndex) <> aryY(lDataIndex - 1) Then
lDataIndex2 = lDataIndex2 + 1
aryX2(lDataIndex2) = aryX(lDataIndex)
aryY2(lDataIndex2) = aryY(lDataIndex)
End If
Next
ReDim Preserve aryX2(1 To lDataIndex2)
ReDim Preserve aryY2(1 To lDataIndex2)
ActiveSheet.Range("B2").Select
Set MyChart = ActiveSheet.Shapes.AddChart(xlXYScatter).Chart
With MyChart
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = ChartName
.SeriesCollection(1).Values = aryY2
.SeriesCollection(1).XValues = aryX2
.Legend.Select
Selection.Delete
.Axes(xlCategory).Select
Selection.TickLabels.NumberFormat = "m/d/yyyy"
Selection.TickLabels.NumberFormat = "[$-409]mmm-dd;@"
.Axes(xlValue).Select
Selection.TickLabels.NumberFormat = "#,##0.00"
Selection.TickLabels.NumberFormat = "#,##0.0"
.Axes(xlValue).HasTitle = True
.Axes(xlValue).AxisTitle.Text = "d80 (um)"
End With
Dim ImageName As String
ImageName = Application.DefaultFilePath & Application.PathSeparator & "TempChart.jpeg"
MyChart.Export filename:=ImageName
ActiveSheet.ChartObjects(1).Delete
ActiveWindow.Zoom = Worksheets("Dashboard").Range("H4").Value
Application.ScreenUpdating = True
A212D80SMD2.Image1.Picture = LoadPicture(ImageName)
End Sub