Excel VBA for dynamic mean weighted ranking

neroed

New Member
Joined
Feb 5, 2018
Messages
1
Hello, I am working on a weighted ranking procedure. I have the procedure written for when it is always rank the top three. The problem is that this needs to be dynamic, it could be any number up to 15 or 20. n is a defined variable and I have a variable called ranknum that identifies how ranks that particular question has. The excel formula would look something like this, =(3*B2+2*C2+D2)/n Any ideas on how to make this dynamic?

Code:
Cells(2, lcol + 3).Activate
    Do While ActiveCell <> ""
       ActiveCell.Offset(0, ranknum + 1).Value = (ActiveCell.Offset(0, ranknum - 2) _
       .Value * 3 + ActiveCell.Offset(0, ranknum - 1).Value _
       * 2 + ActiveCell.Offset(0, ranknum).Value) / n
       ActiveCell.Offset(1, 0).Activate
    Loop
[TABLE="width: 500"]
<tbody>[TR]
[TD]Rank Topic[/TD]
[TD]Rank1[/TD]
[TD]Rank2[/TD]
[TD]Rank3[/TD]
[TD]Weighted[/TD]
[/TR]
[TR]
[TD]Topic1
[/TD]
[TD]3[/TD]
[TD]12[/TD]
[TD]18[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Topic2[/TD]
[TD]24[/TD]
[TD]2[/TD]
[TD]0[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Topic3[/TD]
[TD]1[/TD]
[TD]3[/TD]
[TD]2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Topic4[/TD]
[TD]15[/TD]
[TD]40[/TD]
[TD]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Topic5[/TD]
[TD]2[/TD]
[TD]4[/TD]
[TD]6[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Topic6[/TD]
[TD]12[/TD]
[TD]14[/TD]
[TD]16[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

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