O
oberon.black
I am trying to write a script to allow the information in my user form
to be placed into the next empty column, row, and then I want that
information to be used to create and name a new worksheet that will
copy its data from another existing worksheet. I will attach what I
have done and I hope some one can fix my errors. (this macro is based
on two different macros and I am needing to merge to code to create one
complex macro.). Also I get a Compile Error: Sub or Function not
defined.
Code:
--------------------
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Dim newSheetName As String
Set ws = Worksheet("Class GradeSheet")
newSheetName = iRow
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'check for a part number
If Trim(Me.TextBox56.Value) = "" Then
Me.TextBox56.SetFocus
MsgBox "Please enter a part number"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.TextBox56.Value
ws.Cells(iRow, 2).Value = Me.TextBox55.Value
'clear the data
Me.TextBox56.Value = ""
Me.TextBox55.Value = ""
Me.TextBox56.SetFocus
For Each ws In Worksheets
If ws.Name = newSheetName Or newSheetName = "" Or IsNumeric(newSheetName) Then
MsgBox "Sheet already exists or name is invalid", vbInformation
Exit Sub
End If
Next
Sheets(1).Copy before:=Sheets(1)
Sheets(1).Name = newSheetName
Sheets(newSheetName).Move After:=Sheets(Sheets.Count)
End With
End Sub
to be placed into the next empty column, row, and then I want that
information to be used to create and name a new worksheet that will
copy its data from another existing worksheet. I will attach what I
have done and I hope some one can fix my errors. (this macro is based
on two different macros and I am needing to merge to code to create one
complex macro.). Also I get a Compile Error: Sub or Function not
defined.
Code:
--------------------
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Dim newSheetName As String
Set ws = Worksheet("Class GradeSheet")
newSheetName = iRow
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'check for a part number
If Trim(Me.TextBox56.Value) = "" Then
Me.TextBox56.SetFocus
MsgBox "Please enter a part number"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.TextBox56.Value
ws.Cells(iRow, 2).Value = Me.TextBox55.Value
'clear the data
Me.TextBox56.Value = ""
Me.TextBox55.Value = ""
Me.TextBox56.SetFocus
For Each ws In Worksheets
If ws.Name = newSheetName Or newSheetName = "" Or IsNumeric(newSheetName) Then
MsgBox "Sheet already exists or name is invalid", vbInformation
Exit Sub
End If
Next
Sheets(1).Copy before:=Sheets(1)
Sheets(1).Name = newSheetName
Sheets(newSheetName).Move After:=Sheets(Sheets.Count)
End With
End Sub