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.
 
its right in the actual VB script. I copied those lines from the top sorry for the confusion.
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Just realise it should not be an = sign it should be <> instead.
 
Upvote 0
It switches to the default points page worksheet, then creates the copy at the end of the other worksheets, but does not rename it nor does it make the copied worksheet the active worksheet. and there are no errors coming up during debug or actual use of the button.
 
Upvote 0
In that case can you post your entire code as it stands.
 
Upvote 0
VBA Code:
Sub Points_Import()
    Dim FileToOpen As Variant
    Dim OpenBook As Workbook
    Dim ws As Worksheet

    Set ws = ActiveSheet
   
    Application.ScreenUpdating = False

    FileToOpen = Application.GetOpenFilename(Title:="Browse for your File & Import Range", FileFilter:="Text Files (*.csv*),*csv*")

    If FileToOpen <> False Then
        Set OpenBook = Application.Workbooks.Open(FileToOpen)
        OpenBook.Sheets(1).Range("A1:V45").Copy
        ws.Range("T1").PasteSpecial xlPasteValues
        OpenBook.Close False
    End If

    Application.ScreenUpdating = True
End Sub

Sub Copyrenameworksheet()

Dim ws As Worksheet
Set wh = Worksheets(ActiveSheet.Name)
Worksheets("Default Points Page").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

There seperate macros that i use on different buttons
 
Upvote 0
Other than the fact you have a typo with ws & wh there is nothing wrong with the code. Check that U2 on the sheet that is active when you run the code is not blank.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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