Skip to main content
This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

Previous Next

The rest of the code

I have included some more code that may help.

Sub CreateSheets(xlApp As Variant, strName1 As String, strName2 As String, strName3 As String, strName4 As String)
Dim xlsheet As Variant
Dim xlsheet2 As Variant
Dim xlsheet3 As Variant
Dim xlsheet4 As Variant

'this will create the worksheets beforewe can use them
Set xlsheet = xlApp.Workbooks(1).Worksheets(1)
xlSheet.Activate
xlsheet.Name = strName1
xlsheet.Columns("A:Q").Select
xlApp.Selection.Locked = False


Set xlsheet2 = xlApp.Workbooks(1).Worksheets(2)
xlSheet2.Activate
xlsheet2.Name = strName2
xlsheet2.Columns("A:Q").Select
xlApp.Selection.Locked = False

Set xlsheet3 = xlApp.Workbooks(1).Worksheets(3)
xlSheet3.Activate
xlsheet3.Name = strName3

Set xlsheet4 = xlApp.Workbooks(1).Worksheets.Add(Null,xlsheet3)
xlSheet4.Activate
xlsheet4.Name = strName4

End Sub


Sub SetUpSheet1( xlApp As Variant, strName2 As String, strName3 As String )
' Purpose:
' - set up the first worksheet.
'
Dim vDate As Variant
Dim xlsheet As Variant
Dim intStart As Integer
Dim intTotal As Integer
Dim x As Integer
Dim strStartRow As String
Dim strEndRow As String

vDate = Date
xlApp.StatusBar = "Setting up the summary worksheet. Please be patient..."
Set xlsheet = xlApp.Workbooks(1).Worksheets(1)
xlsheet.Activate

'this will create the headings for the various cloumns.
xlsheet.Cells(1,1).Value = "SUPPORT ENGINEER'S INCENTIVE SCHEME - STATUS REPORT OF - "& vDate
xlsheet.Cells(3,1).Value = Me.YearOfInterest
xlsheet.Cells(3,2).Value = Me.QuarterOfInterest
xlsheet.Cells(3,3).Value = Me.RegionOfInterest
xlsheet.Cells(3,7).Value = "CSat multiplier"
xlsheet.Cells(3,8).Value = "1"

x = Me.intSheet1

xlsheet.Cells(x, 2).Value = "Engineers Name"
xlsheet.Cells(x, 3).Value = "Payroll Number"
xlsheet.Cells(x, 4).Value = "Total Value"
xlsheet.Cells(x, 5).Value = "Total Profit"
xlsheet.Cells(x, 6).Value = "Normal Commission"
xlsheet.Cells(x, 7).Value = "Energy Commission"
xlsheet.Cells(x, 8).Value = "CSat Payment"
xlsheet.Cells(x, 9).Value = "Sales Leads"
xlsheet.Cells(x, 10).Value = "Total Payment"

strStartRow = Cstr( Me.intSheet2 + 1)
strEndRow = Cstr( Me.intSheet2 + Me.intNumberOfQuotes)
'create the entries for all engineers found
Forall elements In Me.lstEngineer
x = x + 1
xlsheet.Cells(x, 2).Value = Listtag( elements )
xlsheet.Cells(x, 3).Value = elements.Payroll
xlsheet.Cells(x, 4).Formula= "=SUMIF('" + strName2 + "'!A:A,""=" + Listtag( elements ) + """,'" + strName2 + "'!E:E" 'elements.SellTotal
xlsheet.Cells(x, 5).Formula = "=SUMIF('" + strName2 + "'!A:A,""=" + Listtag( elements ) + """,'" + strName2 + "'!J:J" ' elements.Profit
xlsheet.Cells(x, 6).Formula = "=SUMPRODUCT(('" + strName2 + "'!A" + strStartRow + ":A" + strEndRow + "=""" + Listtag( elements )+_
""")*('" + strName2 + "'!D" + strStartRow + ":D" + strEndRow + "="""")" +_
"*('" + strName2 + "'!O" + strStartRow + ":O" + strEndRow + "))" ' normal commission
xlsheet.Cells(x, 7).Formula = "=SUMPRODUCT(('" + strName2 + "'!A" + strStartRow + ":A" + strEndRow + "=""" + Listtag( elements )+_
""")*('" + strName2 + "'!D" + strStartRow + ":D" + strEndRow + "<>"""")" +_
"*('" + strName2 + "'!O" + strStartRow + ":O" + strEndRow + "))" ' energy commission


xlsheet.Cells(x, 8).Formula = "=SUM(F" + Cstr(x) + ":G" + Cstr(x) + " ) * ($H$3-1)"
xlsheet.Cells(x, 9).Formula= "=SUMIF('" + strName3 + "'!B:B,C" + Cstr( x ) + ",'" + strName3 + "'!J:J" 'elements.SellTotal
xlsheet.Cells(x, 10).Formula = "=SUM(F" + Cstr(x) + ":I" + Cstr(x) + " )"

End Forall

intTotal = x + 1

xlsheet.Cells(intTotal, 4).Formula = "=SUM(D6:D" + Cstr(x) + ")"
xlsheet.Cells(intTotal, 5).Formula = "=SUM(E6:E" + Cstr(x) + ")"
xlsheet.Cells(intTotal, 6).Formula = "=SUM(F6:F" + Cstr(x) + ")"
xlsheet.Cells(intTotal, 7).Formula = "=SUM(G6:G" + Cstr(x) + ")"
xlsheet.Cells(intTotal, 8).Formula = "=SUM(H6:H" + Cstr(x) + ")"
xlsheet.Cells(intTotal, 9).Formula = "=SUM(I6:I" + Cstr(x) + ")"
xlsheet.Cells(intTotal, 10).Formula = "=SUM(J6:J" + Cstr(x) + ")"

x = intTotal + 2

xlsheet.Cells(x ,7).Value = "Csat Level"
xlsheet.Cells(x ,8).Value = "Multiplier"
x = x + 1
xlsheet.Cells(x ,7).Value = "8.5 or less"
xlsheet.Cells(x ,8).Value = "1"
x = x + 1
xlsheet.Cells(x ,7).Value = "8.5 to 9.0"
xlsheet.Cells(x ,8).Value = "1.2"
x = x + 1
xlsheet.Cells(x ,7).Value = "Above 9.0"
xlsheet.Cells(x ,8).Value = "1.5"

x = x + 2
xlsheet.Cells(x, 2).Value = "INSTRUCTIONS FOR USE"
x = x + 1
xlsheet.Cells(x, 2).Value = "1. Enter the appropriate multiplier for the team's CSAT score in the cell above."
x = x + 1
xlsheet.Cells(x, 2).Value = "2. Specify N in the To be paid column (P) on the Details sheet to stop the bonus being paid for that quote. Please enter why into Reason Not Paid (Q)."
x = x + 1
xlsheet.Cells(x, 2).Value = "3. To stop the energy rate being used for bonus calculations, go back to the view, select the quote(s) and run ""Energy Related\No"". Re-run this report."
x = x + 1
xlsheet.Cells(x, 2).Value = "4. To use the energy rate for the bonus calculation, go back to the view, select the quote(s) and run ""Energy Related\Yes"". Re-run this report."
x = x + 1
xlsheet.Cells(x, 2).Value = "5. Remember to select ALL quotes from the Incentive Scheme view being paid and run ""Mark Bonus Paid."" "
x = x + 2
xlsheet.Cells(x, 2).Value = "WARNING"
x = x + 1
xlsheet.Cells(x, 2).Value = "Do not delete lines from this worksheet as it causes problems on the Payroll sheet. Delete any lines with a 0 payment on the payroll sheet"

Call FormatSheet1(xlApp, intTotal)

End Sub

Sub FormatSheet1(xlApp As Variant, intTotal As Integer)
Dim xlsheet As Variant

Set xlsheet = xlApp.Workbooks(1).Worksheets(1)

xlApp.StatusBar = "Formating Sheet 1. Please be patient..."


'select the title rows and make them bold
xlApp.Range(xlsheet.Cells(1,1), xlsheet.Cells(Me.intSheet1,10)).Select
xlApp.Selection.Font.Bold = True
'select the totals and make it bold
xlSheet.Rows(intTotal).Select

xlApp.Selection.Font.Bold = True

'select the engineer number
'now auto size the sheet
xlApp.Range(xlsheet.Cells(Me.intSheet1,1), xlsheet.Cells(intTotal,10)).Select
xlApp.Selection.Font.Name = "Arial"
xlApp.Selection.Font.Size = 9
xlApp.Selection.Columns.AutoFit
xlApp.Range("D:J").Select
xlApp.Selection.NumberFormat = "#,##0.00"
End Sub

Sub SetUpSheet2(xlApp As Variant)
Dim intQuotes As Integer
Dim intStartRow As Integer
Dim x As Integer
Dim xlsheet As Variant


xlApp.StatusBar = "Setting up the front worksheet. Please be patient..."

Set xlsheet = xlApp.Workbooks(1).Worksheets(2)
xlsheet.Activate

xlsheet.Cells(1,1).Value = "SUPPORT ENGINEER'S INCENTIVE SCHEME - For " & Me.YearOfInterest & " " & Me.QuarterOfInterest & " " & Me.RegionOfInterest

x = Me.intSheet2

xlsheet.Cells(x,1).Value = "Engineer"
xlsheet.Cells(x,2).Value = "Quote Number"
xlsheet.Cells(x,3).Value = "Customer"
xlsheet.Cells(x,4).Value = "Energy"
xlsheet.Cells(x,5).Value = "Sell Price"
xlsheet.Cells(x,6).Value = "Parts Cost"
xlsheet.Cells(x,7).Value = "Labour Cost"
xlsheet.Cells(x,8).Value = "Freight Cost"
xlsheet.Cells(x,9).Value = "Total Cost"
xlsheet.Cells(x,10).Value = "Profit"
xlsheet.Cells(x,11).Value = "Margin"
xlsheet.Cells(x,12).Value = "Order Date"
xlsheet.Cells(x,13).Value = "National"
xlsheet.Cells(x,14).Value = "Order Number"
xlsheet.Cells(x,15).Value = "Commission"
xlsheet.Cells(x,16).Value = "To be paid"
xlsheet.Cells(x,17).Value = "Reason not paid"

x = x + 1

Forall elements In Me.lstEngineer
Call elements.ExtractQuoteDetails (xlApp, xlsheet, Listtag (elements ), x )
x = x + elements.NumberOfQuotes
End Forall


Call FormatSheet2(xlApp,Me.intSheet2, x)

End Sub

Sub FormatSheet2(xlApp As Variant, intHeading As Integer, intEndRow As Integer)
' Purpose
' - format the second worksheet
'
Dim xlsheet As Variant

Set xlsheet = xlApp.Workbooks(1).Worksheets(2)

xlApp.StatusBar = "Formating Sheet 2. Please be patient..."


xlsheet.Cells(1,1).Select
xlApp.Selection.Font.Bold = True
xlSheet.Rows(intHeading).Select
xlApp.Selection.Font.Bold = True

xlApp.Range(xlsheet.Cells(1,1), xlsheet.Cells(intEndRow,19)).Select
xlApp.Selection.Font.Name = "Arial"
xlApp.Selection.Font.Size = 9
xlApp.Range(xlsheet.Cells(intHeading,1), xlsheet.Cells(intEndRow,19)).Select
xlApp.Selection.Columns.AutoFit
xlApp.Range("E:J").Select
xlApp.Selection.NumberFormat = "#,##0.00"
xlApp.Range("L:L").Select
xlApp.Selection.NumberFormat = "dd/mm/yyyy"
xlApp.Range("O:O").Select
xlApp.Selection.NumberFormat = "#,##0.00"

xlApp.Range("D:D").Select
xlApp.Selection.HorizontalAlignment = -4152 ' xlHAlignRight
xlApp.Range("M:Q").Select
xlApp.Selection.HorizontalAlignment = -4152 ' xlHAlignRight

xlSheet.Cells(1,11).Interior.ColorIndex = 46
xlSheet.Cells(1,12).Value = "GM 56 +"
xlSheet.Cells(2,12).Value = "GM 25 to 55"
xlSheet.Cells(3,11).Interior.ColorIndex = 36
xlSheet.Cells(3,12).Value = "GM 1 to 24"
xlSheet.Cells(4,11).Interior.ColorIndex = 3
xlSheet.Cells(4,12).Value = "GM < 1"

' conditional formatting for the margin column
xlApp.Range("K" + Cstr(intHeading+1) + ":K" + Cstr(intEndRow-1) ).Select
xlApp.Selection.FormatConditions.Delete

xlApp.Selection.FormatConditions.Add 1, 5, 55 'xlCellType, xlGreater
xlApp.Selection.FormatConditions(1).Interior.ColorIndex = 46
xlApp.Selection.FormatConditions.Add 1, 1, 1,25 ' xlCellType, xlBetween
xlApp.Selection.FormatConditions(2).Interior.ColorIndex = 36
xlApp.Selection.FormatConditions.Add 1, 6, 1 ' xlCellType, xlLess
xlApp.Selection.FormatConditions(3).Interior.ColorIndex = 3


xlApp.Range(xlsheet.Cells(intHeading+1, 4), xlsheet.Cells(intEndRow-1,4)).Select
xlApp.Selection.Locked = True
xlSheet.Protect "ChangeSourceData"

End Sub


Feedback response number WEBBAHAC4V created by ~Ethan Cisvelumanli on 01/04/2017

Excel 2016 export (~Ethan Cisvelum... 3.Jan.17)
. . Incomplete code! (~Joseph Zekpone... 3.Jan.17)
. . . . The rest of the code (~Ethan Cisvelum... 4.Jan.17)
. . . . . . Possibly a daft question... (~Joseph Zekpone... 4.Jan.17)
. . . . . . . . Create Worksheets (~Ethan Cisvelum... 4.Jan.17)
. . . . . . . . . . More info (~Ethan Cisvelum... 4.Jan.17)
. . . . . . . . . . When you create a blank workbook in... (~Sigmund Umwema... 5.Jan.17)




Printer-friendly

Search this forum

Member Tools


RSS Feeds

 RSS feedsRSS
All forum posts RSS
All main topics RSS