VBA won't paste name to a cell

jondavis1987

Active Member
Joined
Dec 31, 2015
Messages
443
Office Version
  1. 2019
Platform
  1. Windows
This is the vba code. It's supposed to create a copy of a worksheet, delete a button that activates all of this from the copy, give a box to name the new worksheet, alphabetize the worksheet, and then paste that worksheet name in the first empty row of Column A in worksheet Mix Design Names. It does everything except put the name in Mix Design Names. What am I doing wrong?

VBA Code:
Sub New_Superpave2()
    Sheets("Superpave Template").Copy After:=ActiveSheet
    ActiveSheet.Shapes.Range(Array("Option Button 2")).Select
    Selection.Delete
    On Error Resume Next
    ActiveSheet.Name = InputBox("Mix Design Name?")
     
    Dim WS As Worksheet
    Dim lastRow As Long
    
    lastRow = Sheets("Mix Design Names").Cells(Rows.Count, "A").End(xlUp).Row + 1
   Dim strSheetName As String
  strSheetName = ActiveSheet.Name
   Dim SheetMyVar As Worksheet: Set SheetMyVar = ActiveSheet
   
    Sheets("Mix Design Names").Select After:=ActiveSheet
For Each WS In Worksheets

Next WS
   
    Application.ScreenUpdating = False
Dim ShCount As Integer, i As Integer, j As Integer
ShCount = Sheets.Count

For i = 1 To ShCount - 1
    For j = i + 1 To ShCount
        If UCase(Sheets(j).Name) < UCase(Sheets(i).Name) Then
            Sheets(j).Move before:=Sheets(i)
        End If
    Next j
Next i

Application.ScreenUpdating = True
Exit Sub
    Dim wsName As String
      wsName = ActiveSheet.Name
        lastRow = Sheets("Mix Design Names").Cells(Rows.Count, "A").End(xlUp).Row + 1
         WS.Range("A" & lastRow).Value = wsName

SheetMyVar.Select
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
ActiveSheet.Name = InputBox("Mix Design Name?")
This is asking the user to select a name for the worksheet, "Mix Design Name?" is just the prompt in the inputbox. it is not the sheet variable.

VBA Code:
    Dim sh As Worksheet
    Sheets("Superpave Template").Copy After:=ActiveSheet
    Set sh = ActiveSheet
    With sh
        .Name = InputBox("Mix Design Name?")
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1


        'other stuff

    End With
 
Upvote 0
Finally caught my error after walking away

VBA Code:
Sub New_Superpave2()
    Sheets("Superpave Template").Copy After:=ActiveSheet
    ActiveSheet.Shapes.Range(Array("Option Button 2")).Select
    Selection.Delete
    On Error Resume Next
    ActiveSheet.Name = InputBox("Mix Design Name?")
    
    Dim WS As Worksheet
    Dim lastRow As Long
    Dim wsName As String
    wsName = ActiveSheet.Name
    lastRow = Sheets("Mix Design Names").Cells(Rows.Count, "A").End(xlUp).Row + 1
   Dim strSheetName As String
  strSheetName = ActiveSheet.Name
   Dim SheetMyVar As Worksheet: Set SheetMyVar = ActiveSheet
    Sheets("Mix Design Names").Range("A" & lastRow).Value = strSheetName
    Sheets("Mix Design Names").Select After:=ActiveSheet
For Each WS In Worksheets
        
Next WS
   
    Application.ScreenUpdating = False
Dim ShCount As Integer, i As Integer, j As Integer
ShCount = Sheets.Count

For i = 1 To ShCount - 1
    For j = i + 1 To ShCount
        If UCase(Sheets(j).Name) < UCase(Sheets(i).Name) Then
            Sheets(j).Move before:=Sheets(i)
        End If
    Next j
Next i

Application.ScreenUpdating = True
SheetMyVar.Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

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