Problem with VBA Code - Chart

vdalri

New Member
Joined
Jan 15, 2019
Messages
2
Hi Everybody, I am having a problem with Excel VBA codes.
The code that i am trying to do, makes a prediction with the chart. But, i don't know why, every time that i run the code, excel just start not to responding and crash it all.
(I am from Brazil, so, sorry for any english mistake);
It starts to do this after i make that condition with "if":

i = 1
loopp:
If i < fatorm Then
Worksheets("LDT").Cells(i, 7).Value = 1
GoTo loopp
Else
End If

fator = Worksheets("LDT").Range(Sheets("LDT").Cells(1, 7), Sheets("LDT").Cells(i, 7))

-----------------------------

Code:

Private Sub GraficoCapacitancia_Click()


Dim rng As Range
Dim cht As Object
Dim a, b
Dim CurrentSheet As Worksheet
Dim sht As Worksheet
a = Worksheets("LDT").Cells(3, 22)
Dim s As Series
'Your data range for the chart


Set rng = Sheets("LDT").Range(Sheets("LDT").Cells(1, 2), Sheets("LDT").Cells(a, 2))


'Create a chart
Set cht = ActiveSheet.Shapes.AddChart2


'Give chart some data
cht.Chart.SetSourceData Source:=rng


'Determine the chart type

cht.Chart.ChartType = xlXYScatterLines

cht.Name = "Capacitancia"

Dim dias, meddias, fatorm, d, fator, i


meddias = Worksheets("LDT").Cells(2, 19).Value


dias = InputBox("Digite quantos dias adiante a previsão será feita")


d = Day(Now)
fatorm = (dias * meddias) + (Worksheets("LDT").Cells(3, 22).Value)


i = 1
loopp:
If i < fatorm Then
Worksheets("LDT").Cells(i, 7).Value = 1
GoTo loopp
Else
End If


fator = Worksheets("LDT").Range(Sheets("LDT").Cells(1, 7), Sheets("LDT").Cells(i, 7))


Application.ScreenUpdating = False
Application.EnableEvents = False
Set CurrentSheet = ActiveSheet


For Each sht In ActiveWorkbook.Worksheets
For Each cht In sht.ChartObjects
cht.Activate


ActiveChart.SeriesCollection(1).Trendlines.Add(Type:=xlPolynomial, Order:=2, Forward:=0, Backward:=0, DisplayEquation:=True, DisplayRSquared:=False).Select
ActiveChart.SeriesCollection(1).XValues = fator


Next cht
Next sht

With ActiveSheet.Shapes("Capacitancia")
.Left = Range("I1").Left
.Top = Range("I1").Top
End With


End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top