You can use one of the following lines of code:
Application.WorksheetFunction.CountA(Sheets(1).Range("A:A"))
'or
Range("A" & Rows.count).End(xlUp).Row
The first one will count how many cells are in column A. If you have data in rows 1-20, but you have a blank cell in row 10, then it will return 19.
The second one tells you the lowest used row in column A. So in the above scenario it would still tell you 20. It would probably be better for your purposes.
I'm still not sure why you need to do the part with the sum and divide by 3; doesn't the moving average trendline do the same thing? Try this code:
Sub Auto()
'Variables
Dim i As Integer
Dim A1 As Long
Dim nRows As Integer
A1 = Range("A1").Value
nRows = Range("A" & Rows.count).End(xlUp).Row
Range("B1").Value = "Normalized Data"
For i = 2 To nRows
Range("B" & i).Value = Range("A" & i).Value / A1
Next i
'Graphs: linear trendline
ActiveSheet.shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet1'!$B$1:$B$" & nRows) 'change "Sheet1" to your sheet name
ActiveChart.ChartType = xlLine
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
ActiveChart.SetElement (msoElementPrimaryValueAxisTitleRotated)
ActiveChart.SeriesCollection(1).name = "=""Your series title"""
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Your y axis title"
ActiveChart.ChartTitle.Text = "10 days normalized "
ActiveChart.SeriesCollection(1).Trendlines.Add(Type:=xlLinear, Forward:=0, _
Backward:=0, DisplayEquation:=True).Select
'Graphs: 3 day smooth
ActiveSheet.shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet1'!$B$1:$B$" & nRows) 'change "Sheet1" to your sheet name
ActiveChart.ChartType = xlLine
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
ActiveChart.SetElement (msoElementPrimaryValueAxisTitleRotated)
ActiveChart.SeriesCollection(1).name = "=""Your series title"""
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Your y axis title"
ActiveChart.ChartTitle.Text = "3 days normalized "
ActiveChart.SeriesCollection(1).Trendlines.Add(Type:=xlMovingAvg, Period:=3).Select
Selection.name = "Your trendline name here"
End Sub
Or, if you want both trendlines in one chart, that can be arranged as well.
As for not being able to access your module... what do you mean exactly? you push Alt+F11, and what do you see?
-Joe
Bookmarks