Out of Memory error while adding a new line of text

swapnilsaurav

New Member
Joined
Jan 22, 2013
Messages
1
Hi,

I have a long excel sub routine which makes database calls to MS Access almost 25-30 times. I actually have to query the data and then process, which I am doing it in a separate sheet. Then I display the processed data in the active sheet. I want to add another function call in the code, but the problem is, its not allowing me to do so. I get Out of memory error and it automatically deletes the code. However I am able to add comments. Any help would be highly appreciated. I am pasting my code below. The commented line- 'Call CallRectangleWait is what I am trying to add. Not only in this procedure, I am not able to add code to any other procedure. I tried re-starting my machine/doing it on any other machine but no luck.

Sub IndustryHistory()
'Industry All Revenue Segment

Dim lRow, lCol As Long
Dim tSQlQry1 As String
Dim rngTarget As Range

'Call CallRectangleWait
'Clear the excel values
ActiveWorkbook.Sheets("IndustryAllRevSeg").Cells(4, 3) = ActiveWorkbook.Sheets("IndustryBenchmarksSelect").Cells(13, 2)
'Get SIC codes from the database
tSQlQry1 = "Select Distinct [Primary SIC Code] from All_Segments where [myCompany Segment] IN ('" & ActiveWorkbook.Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("A2")
'Add this to a string, append with comma and add to the column
Call RetrieveRecordset(tSQlQry1, rngTarget)
For lRow = 12 To 25
For lCol = 3 To 10
ActiveWorkbook.Sheets("IndustryAllRevSeg").Cells(lRow, lCol).Value = ""
Next lCol
Next lRow
'Gross Margin - DONE
'Current Year
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [Gross Margin (A) @A-0] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(12, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [Gross Margin (A) @A-0] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(12, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [Gross Margin (A) @A-0] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(12, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [Gross Margin (A) @A-0] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(12, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value / 100

'Last Year
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G:G").Clear
tSQlQry1 = "Select [Gross Margin (A) @A-1] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(12, 7).Value = Sheets("IndAllRev_Rough").Cells(5, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H:H").Clear
tSQlQry1 = "Select [Gross Margin (A) @A-1] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(12, 8).Value = Sheets("IndAllRev_Rough").Cells(6, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I:I").Clear
tSQlQry1 = "Select [Gross Margin (A) @A-1] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 1000 AND [TotSales (A) @A-1 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(12, 9).Value = Sheets("IndAllRev_Rough").Cells(7, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J:J").Clear
tSQlQry1 = "Select [Gross Margin (A) @A-1] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(12, 10).Value = Sheets("IndAllRev_Rough").Cells(8, 12).Value / 100

'2 Year back
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U:U").Clear
tSQlQry1 = "Select [Gross Margin (A) @A-2] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(12, 11).Value = Sheets("IndAllRev_Rough").Cells(11, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V:V").Clear
tSQlQry1 = "Select [Gross Margin (A) @A-2] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(12, 12).Value = Sheets("IndAllRev_Rough").Cells(12, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W:W").Clear
tSQlQry1 = "Select [Gross Margin (A) @A-2] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] < 1000 AND [TotSales (A) @A-2 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(12, 13).Value = Sheets("IndAllRev_Rough").Cells(13, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X:X").Clear
tSQlQry1 = "Select [Gross Margin (A) @A-2] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(12, 14).Value = Sheets("IndAllRev_Rough").Cells(14, 12).Value / 100
'SG&A % Revenue - DONE
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [SG&A Exp (A) @A-0 (USD mil)]/[TotSales (A) @A-0 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(13, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [SG&A Exp (A) @A-0 (USD mil)] /[TotSales (A) @A-0 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(13, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [SG&A Exp (A) @A-0 (USD mil)] /[TotSales (A) @A-0 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(13, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [SG&A Exp (A) @A-0 (USD mil)] /[TotSales (A) @A-0 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(13, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value

'Last Year
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G:G").Clear
tSQlQry1 = "Select [SG&A Exp (A) @A-1 (USD mil)] /[TotSales (A) @A-1 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(13, 7).Value = Sheets("IndAllRev_Rough").Cells(5, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H:H").Clear
tSQlQry1 = "Select [SG&A Exp (A) @A-1 (USD mil)] /[TotSales (A) @A-1 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(13, 8).Value = Sheets("IndAllRev_Rough").Cells(6, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I:I").Clear
tSQlQry1 = "Select [SG&A Exp (A) @A-1 (USD mil)] /[TotSales (A) @A-1 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 1000 AND [TotSales (A) @A-1 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(13, 9).Value = Sheets("IndAllRev_Rough").Cells(7, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J:J").Clear
tSQlQry1 = "Select [SG&A Exp (A) @A-1 (USD mil)] /[TotSales (A) @A-1 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(13, 10).Value = Sheets("IndAllRev_Rough").Cells(8, 12).Value

'2 Year back
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U:U").Clear
tSQlQry1 = "Select [SG&A Exp (A) @A-2 (USD mil)] /[TotSales (A) @A-2 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(13, 11).Value = Sheets("IndAllRev_Rough").Cells(11, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V:V").Clear
tSQlQry1 = "Select [SG&A Exp (A) @A-2 (USD mil)] /[TotSales (A) @A-2 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(13, 12).Value = Sheets("IndAllRev_Rough").Cells(12, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W:W").Clear
tSQlQry1 = "Select [SG&A Exp (A) @A-2 (USD mil)] /[TotSales (A) @A-2 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] < 1000 AND [TotSales (A) @A-2 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(13, 13).Value = Sheets("IndAllRev_Rough").Cells(13, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X:X").Clear
tSQlQry1 = "Select [SG&A Exp (A) @A-2 (USD mil)] /[TotSales (A) @A-2 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(13, 14).Value = Sheets("IndAllRev_Rough").Cells(14, 12).Value
'Operating Margin - Oper Margin (A) @A-0
'Current Year
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [Oper Margin (A) @A-0] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(14, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [Oper Margin (A) @A-0] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(14, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [Oper Margin (A) @A-0] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(14, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [Oper Margin (A) @A-0] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(14, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value / 100

'Last Year
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G:G").Clear
tSQlQry1 = "Select [Oper Margin (A) @A-1] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(14, 7).Value = Sheets("IndAllRev_Rough").Cells(5, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H:H").Clear
tSQlQry1 = "Select [Oper Margin (A) @A-1] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(14, 8).Value = Sheets("IndAllRev_Rough").Cells(6, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I:I").Clear
tSQlQry1 = "Select [Oper Margin (A) @A-1] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 1000 AND [TotSales (A) @A-1 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(14, 9).Value = Sheets("IndAllRev_Rough").Cells(7, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J:J").Clear
tSQlQry1 = "Select [Oper Margin (A) @A-1] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(14, 10).Value = Sheets("IndAllRev_Rough").Cells(8, 12).Value / 100

'2 Year back
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U:U").Clear
tSQlQry1 = "Select [Oper Margin (A) @A-2] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(14, 11).Value = Sheets("IndAllRev_Rough").Cells(11, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V:V").Clear
tSQlQry1 = "Select [Oper Margin (A) @A-2] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(14, 12).Value = Sheets("IndAllRev_Rough").Cells(12, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W:W").Clear
tSQlQry1 = "Select [Oper Margin (A) @A-2] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] < 1000 AND [TotSales (A) @A-2 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(14, 13).Value = Sheets("IndAllRev_Rough").Cells(13, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X:X").Clear
tSQlQry1 = "Select [Oper Margin (A) @A-2] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(14, 14).Value = Sheets("IndAllRev_Rough").Cells(14, 12).Value / 100
'Net Income %
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [Net Inc exc E&D (A) @A-0 (USD mil)]/[TotSales (A) @A-0 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(15, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [Net Inc exc E&D (A) @A-0 (USD mil)] /[TotSales (A) @A-0 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(15, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [Net Inc exc E&D (A) @A-0 (USD mil)] /[TotSales (A) @A-0 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(15, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [Net Inc exc E&D (A) @A-0 (USD mil)] /[TotSales (A) @A-0 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(15, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value


Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G:G").Clear
tSQlQry1 = "Select [Net Inc exc E&D (A) @A-1 (USD mil)] /[TotSales (A) @A-1 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(15, 7).Value = Sheets("IndAllRev_Rough").Cells(5, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H:H").Clear
tSQlQry1 = "Select [Net Inc exc E&D (A) @A-1 (USD mil)] /[TotSales (A) @A-1 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(15, 8).Value = Sheets("IndAllRev_Rough").Cells(6, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I:I").Clear
tSQlQry1 = "Select [Net Inc exc E&D (A) @A-1 (USD mil)] /[TotSales (A) @A-1 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 1000 AND [TotSales (A) @A-1 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(15, 9).Value = Sheets("IndAllRev_Rough").Cells(7, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J:J").Clear
tSQlQry1 = "Select [Net Inc exc E&D (A) @A-1 (USD mil)] /[TotSales (A) @A-1 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(15, 10).Value = Sheets("IndAllRev_Rough").Cells(8, 12).Value

'2 Year back
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U:U").Clear
tSQlQry1 = "Select [Net Inc exc E&D (A) @A-2 (USD mil)] /[TotSales (A) @A-2 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(15, 11).Value = Sheets("IndAllRev_Rough").Cells(11, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V:V").Clear
tSQlQry1 = "Select [Net Inc exc E&D (A) @A-2 (USD mil)] /[TotSales (A) @A-2 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(15, 12).Value = Sheets("IndAllRev_Rough").Cells(12, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W:W").Clear
tSQlQry1 = "Select [Net Inc exc E&D (A) @A-2 (USD mil)] /[TotSales (A) @A-2 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] < 1000 AND [TotSales (A) @A-2 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(15, 13).Value = Sheets("IndAllRev_Rough").Cells(13, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X:X").Clear
tSQlQry1 = "Select [Net Inc exc E&D (A) @A-2 (USD mil)] /[TotSales (A) @A-2 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(15, 14).Value = Sheets("IndAllRev_Rough").Cells(14, 12).Value

'1-Year Revenue growth
'Current Year
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [Sales 1yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(16, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [Sales 1yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(16, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [Sales 1yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(16, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [Sales 1yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(16, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value / 100

'3-Year Revenue growth
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [Sales 3yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(17, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [Sales 3yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(17, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [Sales 3yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(17, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [Sales 3yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(17, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value / 100


'Inventory to Revenue % - DONE
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [Inventory (A) @A-0 (USD mil)]/[TotSales (A) @A-0 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(18, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [Inventory (A) @A-0 (USD mil)] /[TotSales (A) @A-0 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(18, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [Inventory (A) @A-0 (USD mil)] /[TotSales (A) @A-0 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(18, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [Inventory (A) @A-0 (USD mil)] /[TotSales (A) @A-0 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(18, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value

'Last year
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G:G").Clear
tSQlQry1 = "Select [Inventory (A) @A-1 (USD mil)] /[TotSales (A) @A-1 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(18, 7).Value = Sheets("IndAllRev_Rough").Cells(5, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H:H").Clear
tSQlQry1 = "Select [Inventory (A) @A-1 (USD mil)] /[TotSales (A) @A-1 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(18, 8).Value = Sheets("IndAllRev_Rough").Cells(6, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I:I").Clear
tSQlQry1 = "Select [Inventory (A) @A-1 (USD mil)] /[TotSales (A) @A-1 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 1000 AND [TotSales (A) @A-1 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(18, 9).Value = Sheets("IndAllRev_Rough").Cells(7, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J:J").Clear
tSQlQry1 = "Select [Inventory (A) @A-1 (USD mil)] /[TotSales (A) @A-1 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(18, 10).Value = Sheets("IndAllRev_Rough").Cells(8, 12).Value

'Last 2 year
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U:U").Clear
tSQlQry1 = "Select [Inventory (A) @A-2 (USD mil)] /[TotSales (A) @A-2 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(18, 11).Value = Sheets("IndAllRev_Rough").Cells(11, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V:V").Clear
tSQlQry1 = "Select [Inventory (A) @A-2 (USD mil)] /[TotSales (A) @A-2 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(18, 12).Value = Sheets("IndAllRev_Rough").Cells(12, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W:W").Clear
tSQlQry1 = "Select [Inventory (A) @A-2 (USD mil)] /[TotSales (A) @A-2 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] < 1000 AND [TotSales (A) @A-2 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(18, 13).Value = Sheets("IndAllRev_Rough").Cells(13, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X:X").Clear
tSQlQry1 = "Select [Inventory (A) @A-2 (USD mil)] /[TotSales (A) @A-2 (USD mil)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(18, 14).Value = Sheets("IndAllRev_Rough").Cells(14, 12).Value

'Sales/Employee
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [Sales/Employee (A)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(19, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [Sales/Employee (A)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(19, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [Sales/Employee (A)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(19, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [Sales/Employee (A)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(19, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value


'Return of Assets (ROA)
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [ROA (A) @A-0] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(20, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [ROA (A) @A-0] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(20, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [ROA (A) @A-0] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(20, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [ROA (A) @A-0] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(20, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value / 100

'Last Year
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G:G").Clear
tSQlQry1 = "Select [ROA (A) @A-1] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(20, 7).Value = Sheets("IndAllRev_Rough").Cells(5, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H:H").Clear
tSQlQry1 = "Select [ROA (A) @A-1] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(20, 8).Value = Sheets("IndAllRev_Rough").Cells(6, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I:I").Clear
tSQlQry1 = "Select [ROA (A) @A-1] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 1000 AND [TotSales (A) @A-1 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(20, 9).Value = Sheets("IndAllRev_Rough").Cells(7, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J:J").Clear
tSQlQry1 = "Select [ROA (A) @A-1] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(20, 10).Value = Sheets("IndAllRev_Rough").Cells(8, 12).Value / 100

' Last 2 year
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U:U").Clear
tSQlQry1 = "Select [ROA (A) @A-2] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(20, 11).Value = Sheets("IndAllRev_Rough").Cells(11, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V:V").Clear
tSQlQry1 = "Select [ROA (A) @A-2] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(20, 12).Value = Sheets("IndAllRev_Rough").Cells(12, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W:W").Clear
tSQlQry1 = "Select [ROA (A) @A-2] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] < 1000 AND [TotSales (A) @A-2 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(20, 13).Value = Sheets("IndAllRev_Rough").Cells(13, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X:X").Clear
tSQlQry1 = "Select [ROA (A) @A-2] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-2 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(20, 14).Value = Sheets("IndAllRev_Rough").Cells(14, 12).Value / 100

'Gross Profit 1 year growth
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [Gross Profit 1yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(21, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [Gross Profit 1yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(21, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [Gross Profit 1yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(21, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [Gross Profit 1yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(21, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value

'Gross Profit 3 year growth
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [Gross Profit 3yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(22, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [Gross Profit 3yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(22, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [Gross Profit 3yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(22, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [Gross Profit 3yr Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(22, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value / 100

'Operating Profit 1 year growth - DONE
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [1 yr Op Inc Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(23, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [1 yr Op Inc Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(23, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [1 yr Op Inc Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(23, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [1 yr Op Inc Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(23, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value / 100

'Operating Profit 3 year growth
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [3 yr Op Inc Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(24, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [3 yr Op Inc Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(24, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [3 yr Op Inc Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(24, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value / 100

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [3 yr Op Inc Gro] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(24, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value / 100

'Days in Inventory - done
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("C:C").Clear
tSQlQry1 = "Select [Days in Inv (A) (0Y)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(25, 3).Value = Sheets("IndAllRev_Rough").Cells(1, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("D:D").Clear
tSQlQry1 = "Select [Days in Inv (A) (0Y)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] >= 1000 "
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(25, 4).Value = Sheets("IndAllRev_Rough").Cells(2, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("E:E").Clear
tSQlQry1 = "Select [Days in Inv (A) (0Y)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 1000 AND [TotSales (A) @A-0 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(25, 5).Value = Sheets("IndAllRev_Rough").Cells(3, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("F:F").Clear
tSQlQry1 = "Select [Days in Inv (A) (0Y)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-0 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(25, 6).Value = Sheets("IndAllRev_Rough").Cells(4, 12).Value

'Last Year
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("G:G").Clear
tSQlQry1 = "Select [Days in Inv (A) (-1Y)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(25, 7).Value = Sheets("IndAllRev_Rough").Cells(5, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("H:H").Clear
tSQlQry1 = "Select [Days in Inv (A) (-1Y)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(25, 8).Value = Sheets("IndAllRev_Rough").Cells(6, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("I:I").Clear
tSQlQry1 = "Select [Days in Inv (A) (-1Y)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 1000 AND [TotSales (A) @A-1 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(25, 9).Value = Sheets("IndAllRev_Rough").Cells(7, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("J:J").Clear
tSQlQry1 = "Select [Days in Inv (A) (-1Y)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(25, 10).Value = Sheets("IndAllRev_Rough").Cells(8, 12).Value

'Last 2 Year
Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("U:U").Clear
tSQlQry1 = "Select [Days in Inv (A) (-2Y)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "')"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(25, 11).Value = Sheets("IndAllRev_Rough").Cells(11, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("V:V").Clear
tSQlQry1 = "Select [Days in Inv (A) (-2Y)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] >= 1000"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(25, 12).Value = Sheets("IndAllRev_Rough").Cells(12, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("W:W").Clear
tSQlQry1 = "Select [Days in Inv (A) (-2Y)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 1000 AND [TotSales (A) @A-1 (USD mil)] >= 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(25, 13).Value = Sheets("IndAllRev_Rough").Cells(13, 12).Value

Set rngTarget = ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X1")
ActiveWorkbook.Sheets("IndAllRev_Rough").Range("X:X").Clear
tSQlQry1 = "Select [Days in Inv (A) (-2Y)] from OnesourceVAData, All_Segments WHERE OnesourceVAData.[SIC Numeric] = All_Segments.[Primary SIC Code] AND All_Segments.[myCompany Segment] IN ('" & Sheets("IndustryAllRevSeg").Cells(4, 3).Value & "') AND [TotSales (A) @A-1 (USD mil)] < 500"
Call RetrieveRecordset(tSQlQry1, rngTarget)
Sheets("IndustryAllRevSeg").Cells(25, 14).Value = Sheets("IndAllRev_Rough").Cells(14, 12).Value

'
'Finally take to the sheet
Sheets("IndustryAllRevSeg").Select
EndoFThis1:
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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