In the following code I have my been able to complete the following task:
my userform will
- add the name entered on it to the selected cells in the activate worksheet (A).
- add the name entered into the userform to the title of a new worksheet (B) tab
- and it will copy the contents of another worksheet to the worksheet (B)
This is great I am so close to completing my goal.
Now, I need to have:
- the name of the worksheet (B) added to a cell in worksheet (B)
- and I want to be able to have the contents of the entire row created in worksheet (A) that shares the name of worksheet (B) be copied over to certain cells in worksheet (B) as they are added to worksheet (A).
So for example:
If I enter John Brown into my userform it will create a row entry in worksheet (A) that says John Brown and it will create worksheet (B) that has the title John Brown and I want to have the name John Brown appear in cell A1 in worksheet (B), then I want to be able to add data to worksheet (A) and have that data fill-in and create cell info from worksheet (A) to worksheet (B) of the same name.
current code
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Dim newSheetName As String
Set ws = Worksheets("Class GradeSheet")
'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 last name"
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
newSheetName = ws.Cells(iRow, 1) & "," & ws.Cells(iRow, 2)
'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("Student Sheet").Copy before:=Sheets(1)
Sheets(1).Name = newSheetName
Sheets(newSheetName).Move After:=Sheets(Sheets.Count)
'close userform
Unload Me
End Sub
Bookmarks