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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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