VBABEGINER
Well-known Member
- Joined
- Jun 15, 2011
- Messages
- 1,284
- Office Version
- 365
- Platform
- Windows
In Module-
------------------------
I have 2 condition in below code,
No. 1 - If user name sheet is available then perform the code
and
No. 2 - If user name sheet is not available then create new sheet name "application.user" and then perform the code
Problem occurred at - No. 1. User name sheet is available but data is not going in user name sheet.
Can any one please help me understand where is the problem..
In User Form-
Code:
Function SheetExists(sheetName As String, Optional Wb As Workbook) As Boolean
If Wb Is Nothing Then Set Wb = ThisWorkbook
On Error Resume Next
SheetExists = (LCase(Wb.Sheets(sheetName).Name) = LCase(sheetName))
On Error GoTo 0
End Function
------------------------
I have 2 condition in below code,
No. 1 - If user name sheet is available then perform the code
and
No. 2 - If user name sheet is not available then create new sheet name "application.user" and then perform the code
Problem occurred at - No. 1. User name sheet is available but data is not going in user name sheet.
Can any one please help me understand where is the problem..
In User Form-
Code:
Private Sub btnsubmit_Click()
Dim sht As Worksheet, NewSh As String
Dim Closed_date As Date, newrow As Long
Application.ScreenUpdating = False
ThisWorkbook.Unprotect "WTW"
If cmbActivity.ListIndex = -1 Then
MsgBox ("Select Activity Type")
ThisWorkbook.Protect "WTW"
Exit Sub
Else
If cmbActivity.Enabled = True Then
If ComboBox1.ListIndex = -1 Then
If cmbActivity.Value = "Core" Then
MsgBox ("Select sub Core Activity")
End If
If cmbActivity.Value = "Non-Core" Then
MsgBox ("Select sub Non - Core Activity")
End If
Else
'Start Non-Core here..
If cmbActivity.Value = "Non-Core" Then
If SheetExists(Me.LblUname.Caption) Then
'Sheets(Me.LblUname.Caption).Select
Sheets(Application.UserName).Select
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.Add after:=Sheets(Sheets.Count)
With Sheets(Sheets.Count)
.Visible = True
.Name = Application.UserName
End With
NewSh = ActiveSheet.Name
Sheets("Sheet1").Visible = True
Sheets("Sheet1").Select
Rows("1:1").Copy
Sheets(NewSh).Activate
Range("A1").PasteSpecial xlPasteValues
Range("A1").PasteSpecial xlPasteFormats
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
Worksheets(NewSh).Visible = False
End If
.
.
Other closing code further..