PC Review


Reply
Thread Tools Rate Thread

Automate Selection

 
 
kaholynn
Guest
Posts: n/a
 
      1st Jan 2009
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.


 
Reply With Quote
 
 
 
 
Socko
Guest
Posts: n/a
 
      1st Jan 2009
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 With Quote
 
kaholynn
Guest
Posts: n/a
 
      1st Jan 2009
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 With Quote
 
Don Guillett
Guest
Posts: n/a
 
      1st Jan 2009
> MsgBox sAssignedWeights
to
sheets("sheet1").range("a1").value=sAssignedWeights


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"kaholynn" <(E-Mail Removed)> wrote in message
news:617D0BBC-8ACC-4007-BD75-(E-Mail Removed)...
> 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 With Quote
 
kaholynn
Guest
Posts: n/a
 
      1st Jan 2009
Great! Thank you so much Don. Your suggestion works.

Thanks,

"Don Guillett" wrote:

> > MsgBox sAssignedWeights

> to
> sheets("sheet1").range("a1").value=sAssignedWeights
>
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "kaholynn" <(E-Mail Removed)> wrote in message
> news:617D0BBC-8ACC-4007-BD75-(E-Mail Removed)...
> > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automate attachment selection Padds Microsoft Outlook Form Programming 12 15th May 2008 05:03 PM
Automate cell selection mayanklal Microsoft Excel Programming 1 12th Jun 2006 04:32 PM
Automate column selection =?Utf-8?B?U25vb3B5?= Microsoft Excel Setup 1 27th Jan 2006 03:26 PM
How to automate contact selection jpottsx1@gmail.com Microsoft Outlook VBA Programming 1 4th Nov 2005 06:50 PM
AUTOMATE DATE SELECTION, PRINT, PDF jlegoland4 Microsoft Excel Programming 0 1st Sep 2004 07:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:21 AM.