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.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Yes but what is the value that is there currently?
 
Upvote 0
='DEFAULT POINTS PAGE'!U2

which is return the value of
Circuit of the Americas - Grand Prix
 
Upvote 0
Right that is too long, a sheet name can only be 31 characters in length.
 
Upvote 0
Still doesnt work even just plain out typed a word in U2 on standing page
 
Upvote 0
In what way doesn't it work?
 
Upvote 0
Is the value for the sheet in U2 on the "Default Points Page" sheet? If so make sure that it's no longer than 31 characters.
 
Upvote 0
VBA Code:
Sub Copyrenameworksheet()

Dim wks As Worksheet
Set wks = ActiveSheet
Worksheets("Default Points Page").Activate
ActiveSheet.Copy After:=Worksheets(Sheets.Count)
Worksheets("Default Points Page (2)").Activate
ActiveSheet.Name = wks.Range("U2").Value
wks.Activate
End Sub

Thanks for all the help. The if statement was screwing it up so i just eliminated it. and it worked.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

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