Activate New worksheet based on cell text

KadenFuhriman

New Member
Joined
Mar 2, 2019
Messages
2
Hey Guys,

I've figured out how to create a bunch of sheets based on some source cells. Now I'm trying to copy the data in the column from each source cell to the page that was created. This is what I've got so far.

Sub AddWorksheetsFromSelection()
Dim CurSheet As Worksheet
Dim Source As Range
Dim c As Range

Set CurSheet = ActiveSheet
Set Source = Selection.Cells
Application.ScreenUpdating = False

For Each c In Source
sName = Trim(c.Text)
If Len(sName) > 0 Then
Worksheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = Trim(c.Text)
CurSheet.Activate
c.Select
ActiveCell.EntireColumn.Copy
Worksheets(Worksheets("Front").c.Text).Activate
Range("A1").PasteSpecial
End If
Next c

CurSheet.Activate
Application.ScreenUpdating = True
End Sub

The line in red is where I've been running into problems. What is the best way to activate the sheet that was just created?

Thanks for the help,

Kaden
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
VBA does not require sheets to be activated or cells selected to copy and paste
This may not be copying what you want, but hopefully you can adapt it to suit your needs

Code:
Sub AddWorksheetsFromSelection()
    Dim CurSheet As Worksheet
    Dim Source As Range
    Dim c As Range
    Dim sName As String, ws As Worksheet
    
    Set CurSheet = ActiveSheet
    Set Source = Selection.Cells
    Application.ScreenUpdating = False
    
    For Each c In Source
    sName = Trim(c.Text)
        If Len(sName) > 0 Then
            Set ws = Worksheets.Add(After:=Worksheets(Worksheets.Count))
            ws.Name = sName
            c.EntireColumn.Copy
            ws.Range("A1").PasteSpecial
        End If
    Next c
    
    CurSheet.Activate
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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