(VBA) Create multiple Invoices based off information from a Master Timesheet

dcoker

New Member
Joined
Dec 13, 2018
Messages
36
I'm at a standstill right now. I have some code that will run when cells in a Column A are selected. These particular cells are only for invoking the code. Each cell is used as a reference cell that is in the same row as the PO used. The code will create a second worksheet (invoice) and name the sheet by the PO.

I need to loop down the Timesheet to look for the same PO within a range and add the contents of the new row to the invoice template.
Each Row is a specific day of the week. So far, this is what I have:

I am very new at this, so any help would be great!


Code:
'~~> Generate Field Ticket
 Dim MySheet As String ' Client PO
 MySheet = ActiveCell.Offset(0, 5).Text
 
 Dim sDate As Variant 'Date that the work was performed
 sDate = ActiveCell.Offset(0, 1).Value
 
 Dim activePO As String
 activePO = ActiveCell.Offset(0, 7).Text
 
 If sDate <> 0 And IsDate(sDate) Then 'Make sure the date is entered correctly
      Dim wb As Workbook
      Dim ws As Worksheet

      Set wb = ActiveWorkbook

      For Each ws In wb.Worksheets

        If ws.Name = MySheet Then 'If a sheet was already generated with this Client PO, simply delete the sheet and generate an updated sheet
        
        Application.DisplayAlerts = False
        Sheets(MySheet).Delete
        Application.DisplayAlerts = True
        End If

      Next 'If the Client PO has not been used yet, then generate a new sheet with the sheet name as the Client PO
      
         Sheets("Template").Visible = True
         Sheets("Template").Copy After:=Sheets(Sheets.Count)
         Sheets("Template").Visible = False
         ActiveSheet.Name = MySheet
         
    Dim i As Integer
    Dim lr As Long
    lr = Sheet2.Cells(Sheet2.Rows.Count, "F").End(xlUp).Row
     
    Dim SourcePO As String 'Client PO during loop
[COLOR=#ff0000]    For i = 7 To lr [/COLOR][COLOR=#008000]'Loop to last row of the timesheet that has been completed[/COLOR][COLOR=#ff0000]
        SourcePO = Sheet2.Range("F" & i).Text
        
        If IsEmpty(Sheet2.Range("A" & i).Value) Then
            Exit Sub
            
        ElseIf IsEmpty(SourcePO) Then
        [/COLOR][COLOR=#008000]'==> go to the next row (Each day is it's own row. Some days below the current row could be blank, so the row needs to be skipped.)[/COLOR][COLOR=#ff0000]
        End If
[/COLOR][COLOR=#008000]
'===> Otherwise assign data to the invoice.
[/COLOR]
Next i



End If
End Sub
 
The macro does not work, it lacks lines and has other errors. You'll have to explain everything you need to make the new macro.
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top