We help IT Professionals succeed at work.
Get Started

I need my existing macro to put cursor focus on a certain worksheet tab

Last Modified: 2014-08-08

I have a macro that I need to tweak in two ways.  it currently creates a new tab and adds a graph.  

1.  I simply need it to place the cursor focus on the worksheet tab titled 'compare plans' after it adds the new tab and graph.   See attached excel with macro...I've also copied the macro below.   (Note that right now the cursor focus ends up in the newly created worksheet instead of the tab titled 'compare plans'.)

2.  I need it to place inside the graph a subtitle = "cell F6" as found in the tab titled 'compare plans'

Here is the current macro:

Sub CopySheetToRecord()
    Dim ws As Worksheet, shName As String, i As Integer
    shName = WorksheetFunction.Text(Sheets("COMPARE PLANS").Range("F14"), "#,###")
    i = 0
    For Each ws In Worksheets
        If ws.Name = shName Then
            i = 1
        End If
    Next ws
    If i = 1 Then
        MsgBox "Sheet " + shName + " exists, copy not performed, program stop", vbCritical
        Sheets("COMPARE PLANS").Copy After:=Sheets(Worksheets.Count)
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        ActiveSheet.Name = shName
        MakeChart (shName)
    End If
End Sub

Sub MakeChart(ByVal shName As String)
    With Sheets(shName)
        .Shapes.AddChart(227, xlLine).Select
        ActiveChart.SetSourceData Source:=.Range("D22:H" & .Range("E1048576").End(xlUp).Row)
        SizeChart (.Shapes("Chart 1"))
    End With
End Sub

Sub SizeChart(ByVal chart As Shape)
    With chart
        .Top = 12
        .Left = 612
        .Height = 350
        .Width = 920
    End With
End Sub

Thanks in advance.
Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE