You are on page 1of 4

lo = 0

hi = nrows - 1
While lo <= hi
mid = lo + (hi - lo) / 2
Dim d1 As Date, d2 As Date
d1 = CDate(Sheets("Completo").Cells(mid, 3))
d2 = CDate(rline(0))
If DateValue(Sheets("Completo").Cells(mid, 3)) = DateValue(rline(0))
Then
If DateDiff("d", d1, d2) < 62 Then
'MsgBox d1
'MsgBox CStr(DateValue(Sheets("Completo").Cells(mid, 3))) + " ug
uale a " + CStr(DateValue(rline(0)))
'MsgBox CStr(TimeValue(rline(0)))
MsgBox d1
MsgBox d2
'MsgBox DateDiff("d", d1, d2)
End If
ElseIf DateValue(Sheets("Completo").Cells(mid, 3)) < DateValue(rline
(0)) Then
lo = mid + 1
Else
hi = mid - 1
End If
Wend

Application.DisplayAlerts = False
Dim I As Long
Dim nrows As Long
'Conteggio righe
For I = 1 To Sheets("Completo").Rows.count()
If IsEmpty(Sheets("Completo").Cells(I, 1).Value) Then
nrows = I
Exit For
End If
Next I
'Cancellazione grafico precedente
Dim WS_Count As Integer
Dim found As Boolean
WS_Count = ActiveWorkbook.Charts.count
For I = 1 To WS_Count
If (ActiveWorkbook.Charts(I).Name = "Grafico") Then
found = True
Exit For
End If
Next I
If found = True Then
ActiveWorkbook.Charts(I).Delete
End If
'Aggiunta nuovo grafico
ActiveWorkbook.Charts.Add

ActiveChart.Name = "Grafico"
ActiveSheet.Shapes.AddChart2(240, xlXYScatterSmoothNoMarkers).Select
ActiveChart.SetSourceData Source:=Range( _
"Completo!$D:$D,Completo!$F:$F,Completo!$G:$G,Completo!$H:$H,Completo!$I
:$I,Completo!$J:$J" _
)
ActiveChart.ChartTitle.text = "MFC Evolution"
With ActiveChart.Parent
.Height = 500 ' resize
.Width = 800 '
.Top = 100
' reposition
.Left = 100 ' reposition
End With
ActiveChart.HasLegend = True
With ActiveChart.Legend
.Font.Size = 8
.Font.Name = "Arial"
.Position = xlLegendPositionBottom
End With
Dim
Dim
Dim
Dim
Dim
Set
Set

pt As Point
p As Long
dl As DataLabel
srs As Series
cht As Chart
cht = ActiveSheet.ChartObjects(1).Chart
srs = cht.SeriesCollection(1)

Dim rline() As String


'Dim lo As Long, mid As Long, hi As Long
Dim d1 As Date, d2 As Date
Dim s As String
Dim pnt As Point
Dim compChart As Chart
Dim labelUp As Boolean
labelUp = True
'Dim dl As DataLabel
'Set compChart = ChartObject("Grafico")
Dim oCs As Chart
For Each oCs In ActiveWorkbook.Charts
If oCs.Name = "Grafico" Then Exit For
Next
Set srs = oCs.ChartObjects(1).Chart.SeriesCollection(1)
Dim myFile As String, text As String, textline As String
myFile = ThisWorkbook.Path & "\Esperimenti_MFC_Carlo.txt"
Open myFile For Input As #1
Do Until EOF(1)
Line Input #1, textline
rline = Split(textline, "-")
'd1 = CDate(Sheets("Completo").Cells(mid, 3))
'd2 = CDate(rline(0))
For I = 2 To nrows - 3
s = Left(Sheets("Completo").Cells(I, 3).Value, Len(CStr(Sheets("Comp

leto").Cells(I, 3).Value)) - 3)
'MsgBox rline(0) + " confronto con " + s
If rline(0) = s Then
With srs.Points(Sheets("Completo").Cells(I, 1).Value)
.HasDataLabel = True
With .DataLabel
.text = rline(0) + " - " + rline(1)
End With
.ApplyDataLabels
End With
Exit For
End If
Next I
Loop
Close #1
ActiveChart.Axes(xlValue).MinimumScale = 0.3
For Each pt In srs.Points
If pt.HasDataLabel = True Then
Set dl = pt.DataLabel
With dl
.HorizontalAlignment = xlCenter
.ReadingOrder = xlLTR
'.Position = xlLabelPositionBestFit
If labelUp = True Then
.VerticalAlignment = xlTop
.Top = 60
labelUp = False
Else
.VerticalAlignment = xlBottom
.Top = 322
labelUp = True
End If
.Orientation = xlHorizontal
'srs.Points(Sheets("Completo").Cells(I, 1).Value).DataLabel.Top
= 250
'.text = rline(0) + " - " + rline(1)
.Font.Size = 7.5
'.Position = xlLabelTop
End With
End If
Next

For Each pt In srs.Points


If pt.HasDataLabel = True Then
Set dl = pt.DataLabel
With dl
.HorizontalAlignment = xlCenter
.ReadingOrder = xlLTR
'.Position = xlLabelPositionBestFit
If labelUp = True Then

.VerticalAlignment = xlTop
.Top = 60
labelUp = False
Else
.VerticalAlignment = xlBottom
.Top = 322
labelUp = True
End If
.Orientation = xlHorizontal
'srs.Points(Sheets("Completo").Cells(I, 1).Value).DataLabel.Top
= 250
'.text = rline(0) + " - " + rline(1)
.Font.Size = 7.5
'.Position = xlLabelTop
End With
End If
Next

You might also like