Sub putval()
Dim Vol_loc, Price_loc, Multi_loc
Dim lsheet As Worksheet
Dim Elem_Vol As Double
Dim Analysis_Period, Multi_Acct As String
Dim Elem_Price As Double
Dim Ctr, Vol_Prd_Ctr, OldSheet, NewSheet As Integer
With ActiveWorkbook.Connections("RPM_Server").OLEDBConnection
.CommandText = "EXECUTE dbo.Key_Acct_Vol '" & Range("b3").Value & "'"
End With
ActiveWorkbook.Connections("RPM_Server").Refresh
' output is pulled in sheet23
For Ctr = 2 To 881
' Vol_loc = "Sheet" & Range("U" & ctr).Value & "!" & Range("V" & ctr).Value
' Vol_loc takes location of volume cell for that element
Vol_loc = Sheet23.Range("C" & Ctr).Value
Price_loc = Sheet23.Range("D" & Ctr).Value
Multi_loc = "K" & Sheet23.Range("E" & Ctr).Value
'lsheet stores the sheet# of the product group for the element
NewSheet = Sheet23.Cells(Ctr, 2).Value
If OldSheet <> NewSheet Then
Set lsheet = ThisWorkbook.Sheets(Sheet23.Cells(Ctr, 2).Value)
OldSheet = NewSheet
End If
' Get volume and price
If Sheet23.Cells(Ctr, Vol_Prd_Ctr).Value <> "" Then
Elem_Vol = Sheet23.Cells(Ctr, Vol_Prd_Ctr).Value
If Analysis_Period = "Quarterly" Then
' Quarterly volume is calculated based on monthly volume
Elem_Vol = Elem_Vol * 3
End If
' Display volume and price in the respective sheets
lsheet.Range(Vol_loc).Value = Elem_Vol
Multi_Acct = Sheet23.Cells(Ctr, 9).Value
Elem_Price = Sheet23.Cells(Ctr, 8).Value
lsheet.Range(Price_loc).Value = Elem_Price
End If
Next
End Sub