Activate sheet copy and paste using cell

Ztcollins

Board Regular
Joined
Jun 4, 2014
Messages
69
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Sub Copyrenameworksheet()

Dim ws As Worksheet
Set wh = Worksheets(ActiveSheet.Name)
Worksheets("Sheet7").Activate
ActiveSheet.Copy After:=Worksheets(Sheets.Count)
If wh.Range("U2").Value "" Then
ActiveSheet.Name = wh.Range("U2").Value
End If
wh.Activate
End Sub


This Macro is set on a Form Controls Button on the Standings Page of the Workboook. The"Sheet7" which is the rootname for the "Default Points Page" i am trying to copy, move to end, and rename it from the cell U2 on that copied sheet.


I have researched this and i am just having a huge brain block on figuring this one out.

VBA Code:
If wh.Range("U2").Value "" Then

This is the syntax error i am getting.

Please and thanks for the help in advance.
 
Yeah its not blank because it is getting data from the points list macro copied and pasted in before i try to run the macro to copy and paste it. after that i have a clear macro that clears my default page.
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
i have even went back and made all those cells where it is pasting in data from the csv file to be text.
 
Upvote 0
But is the same sheet active when you run both codes?
 
Upvote 0
No. First i use the Insert File Button on the Defaults Points Page. It allows me to select the csv file i want to upload. It uploads that data from T1:AO54 As shown in the pic below.

1627324955524.png


Then i go to my Standings Worksheet and Use the Default Copy Button which is where the issue is coming into play. See images below.
1627325118187.png
 
Upvote 0
U2 is blank on that sheet which is why it's not renaming the sheet.
 
Upvote 0
Thought about that. so made this change and the same effect.

VBA Code:
Sub Copyrenameworksheet()

Dim ws As Worksheet
Set wh = Worksheets(ActiveSheet.Name)
Worksheets("Default Points Page").Activate
ActiveSheet.Copy After:=Worksheets(Sheets.Count)
Worksheets("Default Points Page (2)").Activate
If wh.Range("U2").Value <> "" Then
ActiveSheet.Name = wh.Range("U2").Value
End If
wh.Activate
End Sub
 
Upvote 0
So went and add that data to the U2 cell on the standings worksheet now getting a 1004 object error in this line

VBA Code:
ActiveSheet.Name = wh.Range("U2").Value
 
Upvote 0
How about
VBA Code:
Sub Copyrenameworksheet()
   Dim Ws As Worksheet
  
   Set Ws = ActiveSheet
   With Worksheets("Default Points Page")
      If .Range("U2").Value = "" Then Exit Sub
      .Copy After:=Worksheets(Sheets.Count)
      ActiveSheet.Name = .Range("U2").Value
   End With
   Ws.Activate
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,525
Members
449,088
Latest member
RandomExceller01

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