VBABEGINER
Well-known Member
- Joined
- Jun 15, 2011
- Messages
- 1,284
- Office Version
- 365
- Platform
- Windows
Can any one tell me what goes wrong in this code..
LblUname = Label taken on userform
LblUname = Label taken on userform
Code:
Dim x As Integer
Dim y As Integer
Dim NewSh As Worksheet
y = Sheets.Count
For x = 1 To y
If Sheets(x).Name = LblUname Then
NewSh = ActiveSheet.Name
Set sht = Application.Workbooks("Timesheet.xlsm").Sheets(NewSh)
newrow = sht.Cells(Rows.Count, 1).End(xlUp).Row + 1
sht.Cells(newrow, 1) = CDate(Me.txtstartdate)
Closed_date = DateTime.Now
sht.Cells(newrow, 2) = CDate(Closed_date)
'---------------------------------------------
sht.Cells(newrow, 3) = Me.cmbActivity 'Col C
sht.Cells(newrow, 4) = Me.ComboBox1 'sub Type Col D
sht.Cells(newrow, 5) = Me.TxtCaseID 'Col E
sht.Cells(newrow, 6) = Me.TxtEETime 'Col F
'---------------------------------------------
sht.Cells(newrow, 7) = Me.cmbClientName 'Col G
sht.Cells(newrow, 8) = Me.cmbTaskName 'Col H
sht.Cells(newrow, 9) = Me.cmbTaskStatus 'Col I
sht.Cells(newrow, 10) = Me.txtcomm 'Col K
sht.Cells(newrow, 11) = Me.LblUname 'Col L
Workbooks("Timesheet.xlsm").Save
Else
Dim ShName As String
Worksheets("Sheet1").Visible = True
Sheets("Sheet1").Select
With ActiveSheet
ShName = .Name & "Copy"
.Copy After:=Sheets(Worksheets.Count)
End With
'Sheets(Worksheets.Count).Name = ShName
ActiveWorkbook.Worksheets(ShName).Name = LblUname
NewSh = ActiveSheet.Name
Set sht = Application.Workbooks("Timesheet.xlsm").Sheets(NewSh)
newrow = sht.Cells(Rows.Count, 1).End(xlUp).Row + 1
sht.Cells(newrow, 1) = CDate(Me.txtstartdate)
Closed_date = DateTime.Now
sht.Cells(newrow, 2) = CDate(Closed_date)
'---------------------------------------------
sht.Cells(newrow, 3) = Me.cmbActivity 'Col C
sht.Cells(newrow, 4) = Me.ComboBox1 'sub Type Col D
sht.Cells(newrow, 5) = Me.TxtCaseID 'Col E
sht.Cells(newrow, 6) = Me.TxtEETime 'Col F
'---------------------------------------------
sht.Cells(newrow, 7) = Me.cmbClientName 'Col G
sht.Cells(newrow, 8) = Me.cmbTaskName 'Col H
sht.Cells(newrow, 9) = Me.cmbTaskStatus 'Col I
sht.Cells(newrow, 10) = Me.txtcomm 'Col K
sht.Cells(newrow, 11) = Me.LblUname 'Col L
Workbooks("Timesheet.xlsm").Save
Worksheets("Sheet1").Visible = False
Exit Sub
End If
Next x