If you want to select all of the cells in a sheet from a specific start point (set to A2 in my code below) then I usually use a LastRow and LastCol function for this. There are lots of different ways to get the last row / column, I have included what I normally use.
I have also added to your code and put this inside a procedure named Main. This loops through each sheet in the workbook and gets the range as described above and then goes into the code that you posted. As I do not have the data in your sheets I have not been able to test the code for the charts itself:
Sub main()
Const cStartCell As String = "A2"
Dim vLastRow As Long, vLastCol As String
Dim vRange As Range
Dim vSheet As Worksheet
For Each vSheet In Application.ActiveWorkbook.Sheets
vLastRow = LastRow(vSheet.Name)
vLastCol = LastCol(vSheet.Name)
Set vRange = vSheet.Range(cStartCell & ":" & vLastCol & vLastRow)
Debug.Print "Sheet " & vSheet.Name & ", vRange set to address range: " & vRange.Address()
vSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range(vRange)
ActiveChart.ChartType = xlLineStacked
ActiveChart.SetSourceData (vRange)
Next vSheet
End Sub
Function LastRow(pSheet As String)
On Error GoTo LastRow_err
LastRow = Sheets(pSheet).UsedRange.Rows.Count
LastRow_exit:
Exit Function
LastRow_err:
Debug.Print "Error in LastRow function", vbCrLf, "Err no: ", _
Err.Number, vbCrLf, "Err Description: ", Err.Description
End Function
Function LastCol(pSheet As String)
On Error GoTo LastCol_err
LastCol = ColNoToLetter(Sheets(pSheet).UsedRange.Columns.Count)
LastCol_exit:
Exit Function
LastCol_err:
Debug.Print "Error in LastCol function", vbCrLf, "Err no: ", _
Err.Number, vbCrLf, "Err Description: ", Err.Description
End Function
Function ColNoToLetter(pColNo As Integer)
On Error GoTo ColNoToLetter_err
' Goes from currently active cell and finds the next available row
' Local constants / variables
Const cProcName = "ColNoToLetter"
Dim vNumberOne As Integer
Dim vNumberTwo As Integer
Dim vLetterOne As String
Dim vLetterTwo As String
vNumberOne = 0
vNumberTwo = 0
vLetterOne = Empty
vLetterTwo = Empty
vNumberOne = Int((pColNo - 1) / 26)
vNumberTwo = pColNo - (vNumberOne * 26)
vLetterTwo = Chr(vNumberTwo + 64)
If vNumberOne >= 1 Then
vLetterOne = Chr(vNumberOne + 64)
End If
ColNoToLetter = vLetterOne & vLetterTwo
ColNoToLetter_exit:
Exit Function
ColNoToLetter_err:
Debug.Print "Error in ColNoToLetter function", vbCrLf, "Err no: ", _
Err.Number, vbCrLf, "Err Description: ", Err.Description
Resume Next
End Function
Let me know if you have any questions about how the code works etc.