VB2: The code

Mar 16, 2006 13:45

Sub Scorecard()
'
' Scorecard Macro
' Macro recorded 3/14/2006 by Matrixboarder
'

' Variables
Dim FirstCell As String
Dim LastCell As String
Dim Row As Long

' Create a Scorecard worksheet from copy of Template worksheet
Sheets("Template").Select
Sheets("Template").Copy Before:=Sheets(1)

' Fill in Chart in Scorecard worksheet using data from Data worksheet
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select

''''''''''''''''''''''''''''''''''''''''''''
' This Method graphs until Row 31 all the time.
' But it is supposed to check for the last row used and graph until that row only.
'''''''''''''''''''''''''''''''''''''''''''

LastRow = Sheets("Data").UsedRange.Rows.Count
LastCell = "B" & Mid$(Str$(LastRow), 2)
ActiveChart.SetSourceData Source:=Sheets("Data").Range("A4:" & LastCell), PlotBy:= _
xlColumns

' Rename worksheet and failsafe already existing name
ActNm = ActiveSheet.Name
On Error Resume Next
Sheets("Template (2)").Select
ActiveSheet.Name = InputBox("Provide name for new worksheet.")
' Sheets("Template (2)").Name = "Scorecard"
NoName: If Err.number = 1004 Then
ActiveSheet.Name = InputBox("Name already exists. Provide new name.")
If ActiveSheet.Name = ActNm Then
GoTo NoName
End If
End If
On Error GoTo 0

End Sub
Previous post Next post
Up