Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Automate Selection
Hi,
I need to assign weights to three groups. W1 , W2, and W3. Summation of weights will always be 1.0. How one can assign weights with respect to a discrete level . Example if the discrete level is 0.5 then options for W1, W2, and W3 can be 1 , 0, 0 0, 1, 0 0, 0, 1 0.5, 0.5 , 0 0.5, 0, 0.5 0, 0.5, 0.5 I was wondering if we can automate the process of assigning weights for higher discrete level. Example, 0.1 or even lesser. My apologies if I am not clear in explaining the problem. I will appreciate any replies. Thank you so much. |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Automate Selection
Take a look at the following vba procedure, paste it in your code
window and run it. Sub AssignWeight() Dim i, j, k As Double Dim First, Second, Third As Double Dim DiscreteLevel As Double Dim sAssignedWeights As String DiscreteLevel = 0.05 For i = 0 To 1 Step DiscreteLevel For j = 0 To 1 Step DiscreteLevel For k = 0 To 1 Step DiscreteLevel If i + j + k = 1 Then First = i Second = j Third = k sAssignedWeights = sAssignedWeights & vbNewLine & _ First & ", " & Second & ", " & Third End If Next k Next j Next i MsgBox sAssignedWeights End Sub I hope this helps - Selva V Pasupathy For more on VBA, Excel, & Other Programming Please visit http://socko.wordpress.com |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Automate Selection
Selva,
Thank you so much. The VBA code works. Just have a question (I am new to VBA codes). How to view the results in a worksheet (example sheet1) instead of the message box (MsgBox). I cannot view all the assigned weights. Many thanks. -- "Socko" wrote: Take a look at the following vba procedure, paste it in your code window and run it. Sub AssignWeight() Dim i, j, k As Double Dim First, Second, Third As Double Dim DiscreteLevel As Double Dim sAssignedWeights As String DiscreteLevel = 0.05 For i = 0 To 1 Step DiscreteLevel For j = 0 To 1 Step DiscreteLevel For k = 0 To 1 Step DiscreteLevel If i + j + k = 1 Then First = i Second = j Third = k sAssignedWeights = sAssignedWeights & vbNewLine & _ First & ", " & Second & ", " & Third End If Next k Next j Next i MsgBox sAssignedWeights End Sub I hope this helps - Selva V Pasupathy For more on VBA, Excel, & Other Programming Please visit http://socko.wordpress.com |
#5
Posted to microsoft.public.excel.misc
|
|||
|
|||
Automate Selection
Great! Thank you so much Don. Your suggestion works.
Thanks, "Don Guillett" wrote: MsgBox sAssignedWeights to sheets("sheet1").range("a1").value=sAssignedWeight s -- Don Guillett Microsoft MVP Excel SalesAid Software "kaholynn" wrote in message ... Selva, Thank you so much. The VBA code works. Just have a question (I am new to VBA codes). How to view the results in a worksheet (example sheet1) instead of the message box (MsgBox). I cannot view all the assigned weights. Many thanks. -- "Socko" wrote: Take a look at the following vba procedure, paste it in your code window and run it. Sub AssignWeight() Dim i, j, k As Double Dim First, Second, Third As Double Dim DiscreteLevel As Double Dim sAssignedWeights As String DiscreteLevel = 0.05 For i = 0 To 1 Step DiscreteLevel For j = 0 To 1 Step DiscreteLevel For k = 0 To 1 Step DiscreteLevel If i + j + k = 1 Then First = i Second = j Third = k sAssignedWeights = sAssignedWeights & vbNewLine & _ First & ", " & Second & ", " & Third End If Next k Next j Next i MsgBox sAssignedWeights End Sub I hope this helps - Selva V Pasupathy For more on VBA, Excel, & Other Programming Please visit http://socko.wordpress.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Automate pivot table selection | Excel Discussion (Misc queries) | |||
Copy Selection - Transpose Selection - Delete Selection | Excel Discussion (Misc queries) | |||
Identifying a selection of a selection of a range | Excel Worksheet Functions | |||
Automate selection of specific reference cells | Excel Discussion (Misc queries) | |||
Automate column selection | Setting up and Configuration of Excel |