VBA won't paste name to a cell

jondavis1987

Active Member
Joined
Dec 31, 2015
Messages
416
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
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

davesexcel

Well-known Member
Joined
Feb 26, 2006
Messages
1,089
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
 

jondavis1987

Active Member
Joined
Dec 31, 2015
Messages
416
Office Version
  1. 2019
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,127,133
Messages
5,622,922
Members
415,940
Latest member
franzL

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
Top