I am working on a spreadsheet in which I have data of quarter-wise sales by co. and sector. My data is arranged in below mentioned format: Row 1 has date Data starts from row 2 Column B: Company Name Column C: Sector Name of the co. for ex. energy, materials, technology etc Column D: Sales figure of co. Column E, F, G: Price, shares, volume of co. Column H: Blank
From next column onwards I have same data fields for next quarter Column I: Company Name Column J: Sector Name of the co. for ex. energy, materials, technology etc Column K: Sales figure of co So on and so forth
Now, in another worksheet I need to get name and sales figures for top 3/5/10/15 etc (top n co.s depending on user input) within each sector. For ex. sales figures and co. name of top 3 companies in Energy sector. I have been trying to write a vba code for this but I am struggling. I have mentioned below the code I was trying but its not flexible at all since in my code I have given reference of column C and D which would actually change after each quarter
Can someone help. Would be highly appreciated.
Sub try()
Dim r As Long
n = Range("topcos").Value + 5
For r = 5 To n
p = 1
Worksheets("Top co. share with co name").Activate
Cells(r, 16).Select
Selection.FormulaArray = "=LARGE(IF('Co Wise'!$C$3:$C$600=P$3,'Co Wise'!$D$3:$D$600,""""),p)"
p = p + 1
Next r
End Sub
Aucun commentaire:
Enregistrer un commentaire