I have my code 90% working but cant figure out this last thing. I am automating a trip tracker for use throughout the company and the file will be sent out, with no team members added, to the team leads to start tracking trips. I have the current code setup to create a sheet for each new user added where the individual will insert the trips completed and the trips will automatically get filled out in monthly sheets. At the top of the sheet I have the days and the new user name getting filled out. I need to paste the range at the top of the sheet for each month to the last row of the month nut can't get it to work. I'm sure its something stupid like syntax error cause I've adapted most of this code from other sources and don't really know VBA.
I was thinking of an iRow2 but don't think it pertains to what I'm trying to do. Also cant define the cell to paste because as users are added the final row moves. I have labeled below what I have tried including a super dumbed down version of it. I have the others months not active because I'm trying to figure out one month before the others. Anything to help or to reduce the size of code and make it more efficient would be greatly appreciated.
I was thinking of an iRow2 but don't think it pertains to what I'm trying to do. Also cant define the cell to paste because as users are added the final row moves. I have labeled below what I have tried including a super dumbed down version of it. I have the others months not active because I'm trying to figure out one month before the others. Anything to help or to reduce the size of code and make it more efficient would be greatly appreciated.
VBA Code:
Private Sub AddUserButton_Click()
Dim iRow1 As Long
Dim iRow2 As Long
Dim ws As Worksheet
Dim Tbl As ListObject
'Find first empty row in Users List
iRow1 = Sheets("Summary").Range("S" & Rows.Count).End(xlUp).Row + 1
'copy the data to the database, use protect and unprotect lines with your password if worksheet is protected
With Worksheets("Summary")
.Unprotect Password:=""
.Cells(iRow1, 19).Value = Trim(Me.txtFirstName.Value)
.Cells(iRow1, 20).Value = Trim(Me.txtLastName.Value)
'.Protect Password:=""
End With
'Make New Sheet for new user
Worksheets("Template").Copy Before:=Worksheets("End")
ActiveSheet.Name = Trim(Me.txtFirstName.Value) & " " & Trim(Me.txtLastName.Value)
'Insert New user name in Month sheet rows
Sheets("Jan").Range("B1:B31") = Trim(Me.txtFirstName.Value) & " " & Trim(Me.txtLastName.Value)
'Sheets("Feb").Range("B1:B29") = Trim(Me.txtFirstName.Value) & " " & Trim(Me.txtLastName.Value)
'Sheets("March").Range("B1:B31") = Trim(Me.txtFirstName.Value) & " " & Trim(Me.txtLastName.Value)
'Sheets("April").Range("B1:B30") = Trim(Me.txtFirstName.Value) & " " & Trim(Me.txtLastName.Value)
'Sheets("May").Range("B1:B31") = Trim(Me.txtFirstName.Value) & " " & Trim(Me.txtLastName.Value)
'Sheets("June").Range("B1:B30") = Trim(Me.txtFirstName.Value) & " " & Trim(Me.txtLastName.Value)
'Sheets("July").Range("B1:B31") = Trim(Me.txtFirstName.Value) & " " & Trim(Me.txtLastName.Value)
'Sheets("Aug").Range("B1:B31") = Trim(Me.txtFirstName.Value) & " " & Trim(Me.txtLastName.Value)
'Sheets("Sept").Range("B1:B30") = Trim(Me.txtFirstName.Value) & " " & Trim(Me.txtLastName.Value)
'Sheets("Oct").Range("B1:B31") = Trim(Me.txtFirstName.Value) & " " & Trim(Me.txtLastName.Value)
'Sheets("Nov").Range("B1:B30") = Trim(Me.txtFirstName.Value) & " " & Trim(Me.txtLastName.Value)
'Sheets("Dec").Range("B1:B31") = Trim(Me.txtFirstName.Value) & " " & Trim(Me.txtLastName.Value)
'Copy a months days with New user name in month sheets
Sheets("Jan").Range("A1:B31").Copy Destination:=Sheets("Jan").Range("A" & Rows.Count).End(x1Up).Row + 1 'didnt work
Sheets("Jan").Select 'didnt work
Range("A1:B31").Select
Selection.Copy
iRow2 = Sheets("Jan").Range("A" & Rows.Count).End(xlUp).Row + 1 'didnt work
.Cells(iRow2, 1).Value = .Paste
ActiveSheet.Paste
'Sheets("Jan").Range("A1:B29").EntireRow.Copy Destination:=Sheets("Jan").Range("A" & RowsCount).End(x1Up).Offset(1, 0) 'didnt work
'Sheets("Jan").Range("A1:B29").EntireRow.Copy Destination:=Sheets("Jan").Range("A" & Rows.Count).End(x1Up).Offset(1, 0) 'didnt work
'Sheets("Feb").Range("A1:B30").EntireRow.Copy Destination:=Sheets("Feb").Range("A" & RowsCount).End(x1Up).Offset(1, 0)
'Sheets("March").Range("A1:B30").EntireRow.Copy Destination:=Sheets("March").Range("A" & RowsCount).End(x1Up).Offset(1, 0)
'Sheets("April").Range("A1:B30").EntireRow.Copy Destination:=Sheets("April").Range("A" & RowsCount).End(x1Up).Offset(1, 0)
'Sheets("May").Range("A1:B31").EntireRow.Copy Destination:=Sheets("May").Range("A" & RowsCount).End(x1Up).Offset(1, 0)
'Sheets("June").Range("A1:B30").EntireRow.Copy Destination:=Sheets("June").Range("A" & RowsCount).End(x1Up).Offset(1, 0)
'Sheets("July").Range("A1:B31").EntireRow.Copy Destination:=Sheets("July").Range("A" & RowsCount).End(x1Up).Offset(1, 0)
'Sheets("Aug").Range("A1:B31").EntireRow.Copy Destination:=Sheets("Aug").Range("A" & RowsCount).End(x1Up).Offset(1, 0)
'Sheets("Sept").Range("A1:B30").EntireRow.Copy Destination:=Sheets("Sept").Range("A" & RowsCount).End(x1Up).Offset(1, 0)
'Sheets("Oct").Range("A1:B31").EntireRow.Copy Destination:=Sheets("Oct").Range("A" & RowsCount).End(x1Up).Offset(1, 0)
'Sheets("Nov").Range("A1:B30").EntireRow.Copy Destination:=Sheets("Nov").Range("A" & RowsCount).End(x1Up).Offset(1, 0)
'Sheets("Dec").Range("A1:B31").EntireRow.Copy Destination:=Sheets("Dec").Range("A" & RowsCount).End(x1Up).Offset(1, 0)
'Delete New user names to set as blank again
Sheets("Jan").Range("B1:B31") = ""
'Sheets("Feb").Range("B1:B29") = ""
'Sheets("March").Range("B1:B31") = ""
'Sheets("April").Range("B1:B30") = ""
'Sheets("May").Range("B1:B31") = ""
'Sheets("June").Range("B1:B30") = ""
'Sheets("July").Range("B1:B31") = ""
'Sheets("Aug").Range("B1:B31") = ""
'Sheets("Sept").Range("B1:B30") = ""
'Sheets("Oct").Range("B1:B31") = ""
'Sheets("Nov").Range("B1:B30") = ""
'Sheets("Dec").Range("B1:B31") = ""
'Clear names from the box
Me.txtFirstName.Value = ""
Me.txtLastName.Value = ""
'Focus on First name for another entry
Me.txtFirstName.SetFocus
'Rename all table the name of sheet
For Each ws In Worksheets
For Each Tbl In ws.ListObjects
Tbl.Name = ws.Name
Exit For
Next Tbl
Next ws
'Go to Summary page
End Sub