I have created a macro to add a new entry, via inputbox, to my "Summary Sheet" and then add a worksheet named after that new entry. I am trying to find a way to link cells in the same row as the new entry on the Summary Sheet to corresponding cells in my newly added sheet. My problem (I think ) is referencing a sheet for which I won't know the name until after it is created.
One other thing I should add - I may have to adjust it later to be a formula based upon the data in the cell on the newly added sheet, rather than just being equal to the cell.
Any suggestions are appreciated! My code is below:
One other thing I should add - I may have to adjust it later to be a formula based upon the data in the cell on the newly added sheet, rather than just being equal to the cell.
Any suggestions are appreciated! My code is below:
Code:
Sub TestAttendance()
' TestAttendance Macro
Rows("4:4").Select
Selection.Insert Shift:=xlDown
Range("A4").Select
ActiveCell.FormulaR1C1 = InputBox("EMPLOYEE NAME (Example: Doe,John S.)")
If ActiveCell.FormulaR1C1 <> vbNullString Then
Range("A4:B4").Select
With Selection
Selection.Merge
.HorizontalAlignment = xlLeft
End With
Sheets("Attendance").Select
Cells.Select
Selection.Copy
Sheets("Attendance").Select
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = Sheets("Summary Sheet").Range("A4")
Cells.Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("D3").Select
ActiveCell.FormulaR1C1 = Sheets("Summary Sheet").Range("A4")
Sheets("Summary Sheet").Select
Range("B4").FormulaR1C1 = "=MySheet!R[-1]C[3]"
Range("C4").FormulaR1C1 = "='MySheet'!R[68]C[33]"
Range("D4").FormulaR1C1 = "='MySheet'!R[69]C[32]"
Range("E4").FormulaR1C1 = "='MySheet'!R[70]C[31]"
Range("F4").FormulaR1C1 = "='MySheet'!R[67]C[30]"
Range("G4").FormulaR1C1 = "=SUM(RC[-4]:RC[-1])"
Range("A1").Select
ElseIf ActiveCell.FormulaR1C1 = vbNullString Then Exit Sub
End If
End Sub
Last edited: