Dim aa As Integer
Dim StartDate As String
Dim StartDate3 As Range
Dim EndDate As String
Dim EndDate3 As Range
Dim RngStart As Range
Dim RngEnd As Range
Dim RngEnd2 As Range
Dim sh As Worksheet
Dim chrt As ChartObject
Dim ch As Chart
Dim zz As Integer
Dim NumObs2 As Long
NumObs2 = Sheets("AllDistanceMeasures").Cells(Rows.Count, 3).End(xlUp).Row 'gets last row of range
'Changed from Rows.Count to Row so loop will go to end of column.
For aa = 5 To NumObs2
StartDate = ActiveWorkbook.Sheets("AllDistanceMeasures").Cells(aa, 9).Value
EndDate = ActiveWorkbook.Sheets("AllDistanceMeasures").Cells(aa, 10).Value
Set RngStart = Sheet("ActiveSheet").Cells.Find(What:=StartDate, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If RngStart Is Nothing Then
MsgBox "Variable did not set for 'RngStart'. Check criteria value.", vbExclamation, "ALERT"
Exit Sub
End If
Set RngEnd = Sheet("ActiveSheet").Cells.Find(What:=EndDate, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Offset(0, 1)
If RngEnd Is Nothing Then
MsgBox "Variable did not set for 'RngEnd'. Check criteria value.", vbExclamation, "ALERT"
Exit Sub
End If
Set RngEnd2 = Sheet("ActiveSheet").Cells.Find(What:=EndDate, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If RngEnd2 Is Nothing Then
MsgBox "Varible did not set for 'RngEnd2'. Check criteria value.", vbExclamation, "ALERT"
Exit Sub
End If
'Set StartDate3 = ActiveWorkbook.Sheets("ActiveSheet").Range(RngStart)
'Set EndDate3 = ActiveWorkbook.Sheets("ActiveSheet").Range(RngEnd).Offset(0, 1)
Set sh = Worksheets("LowDistCharts")
Set chrt = sh.ChartObjects.Add(0, 0, 300, 300)
Set ch = chrt.Chart
With chrt
.Height = 300
.Width = 300
.Top = 1 + ((aa - 4) * 300)
.Left = 1
End With
With ch
.HasTitle = True
.ChartTitle.Text = aa & " " & StartDate & " to " & EndDate
.ChartTitle.Font.Size = 8
.ChartType = xlLine
'.SetSourceData Source:=Sheets("ActiveSheet").Range(StartDate3, EndDate3)
.SeriesCollection.Add (ActiveWorkbook.Worksheets(DataSht).Range(DataRange))
'.SeriesCollection.Add (ActiveWorkbook.Worksheets("ActiveSheet").Range(RngStart, RngEnd))
.SeriesCollection(1).AxisGroup = 2
.HasLegend = False
End With
For zz = 0 To NumObs - 1
Sheets("ActiveSheet").Range(RngEnd2).Offset(zz, 0).Resize(, 2).Copy
Sheets("LowDistCharts").Cells(5, aa * 2 + 5).Offset(zz, 0).PasteSpecial xlPasteValues
Next zz
'ActiveWorkbook.Sheets("ActiveSheet").Range(StartDate, EndDate).Resize(, 2).Copy
'Sheets("LowDistCharts").Range("S3").End(xlToRight).Offset(0, 1).PasteSpecial xlPasteValues
Next aa