Hi there
I have a problem. My code works perfect, but now I want to, instead of displaying multiple sheets, display all data in one sheet. Below is my code I used:
Private Sub Picture2_Click()
Screen.MousePointer = vbHourglass
Dim tempAss As String
Dim xlApp As Excel.Application
Dim wb As Workbook
Dim ws As Worksheet
Dim hold() As String
Dim g As Integer
Set xlApp = New Excel.Application
Set wb = xlApp.Workbooks.Open(folder & "Templates\Expense Report.xls")
Dim oucnt As Integer
Dim expense_amount As Single
expense_amount = 0
outcnt = 0
Dim E_temp1() As String
Dim E_temp2() As String
For j = 0 To assistants.ListCount - 1
If assistants.Selected(j) Then
For i = 0 To nu - 1
If assistants.List(j) = userlog(i).UName Then
g = 0
Call Read_TMdata(userlog(i).UID + ".txt")
Set ws = wb.Worksheets(assistants.List(j)) 'Specify your worksheet name
For k = 0 To TMcnt - 1
If TMdata(k).Expenses <> "" Then
If DateValue(TMdata(k).EDate) >= DateValue(Label4.Caption) And DateValue(TMdata(k).EDate) <= Label6.Caption Then
E_temp1 = Split(TMdata(k).Expenses, "$$")
For ep = 0 To UBound(E_temp1)
If E_temp1(ep) <> "" Then
E_temp2 = Split(E_temp1(ep), vbTab)
If E_temp2(0) <> "" Then
ws.Cells(g + 4, 1).Value = TMdata(k).EDate
If InStr(1, TMdata(k).JobCode, "%d%", 1) <> 0 Then
hold() = Split(TMdata(k).JobCode, "%d%")
ws.Cells(g + 4, 2).Value = hold(0)
Else
ws.Cells(g + 4, 2).Value = TMdata(k).JobCode
End If
For n = 0 To nu - 1
If userlog(n).UID = TMdata(k).UID Then
ws.Cells(g + 4, 3).Value = userlog(n).UName
End If
Next n
ws.Cells(g + 4, 3).Value = E_temp2(0)
ws.Cells(g + 4, 4).Value = E_temp2(6)
ws.Cells(g + 4, 5).Value = E_temp2(7)
ws.Cells(g + 4, 6).Value = CSng(E_temp2(6)) * CSng(E_temp2(7))
expense_amount = expense_amount + (CSng(E_temp2(6)) * CSng(E_temp2(7)))
End If
g = g + 1
End If
Next ep
End If
End If
Next k
End If
Next i
End If
Next j
Call Read_TMdata(user.UID + ".txt")
xlApp.Visible = True
Set ws = Nothing
Set wb = Nothing
Set xlApp = Nothing
Screen.MousePointer = vbDefault
End Sub
Can anyone help me please?