select data and ask me what action needs to be done?

gauti

New Member
Joined
Dec 16, 2016
Messages
21
I have table like below. Is it possible to write something up to show on a separate sheet or on a popup the parameters( age etc) and give me an option to choose wether I want an average or std Deviation of the data set for each parameter.

Example table:

ParameterSET1SET2SET3
Age51520
height110160180
abc555522
XYZ122356

<tbody>
</tbody>


output something like: (I want the code to ask me what to do for each parameter - avg or std deviation)

IS it possible to do something like this

ParameterStd Deviation or AverageResult
AgeAvgAvg= 5
heightStdStd = 7
abcAvg
xyzStd

<tbody>
</tbody>
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try this, where you will copy this code to the worksheet module, with your Example Data in A2:D5.

I don't know 'nutin about STDV, just using what I found in the Excel functions and the average is the plain-jane AVERAGE(range).

Select a Parameter in column A and read/follow the prompts.

Howard

Code:
Option Explicit
Private Sub Worksheet_selectionChange(ByVal Target As Range)
  Dim rng As Range
  Dim rngFound As Range
  Dim myFnd As String
  Dim Msg, ans, Cancel
  Dim setRng As Range
  
   If Target.Count > 1 Then Exit Sub
   
   Set rng = Target.Parent.Columns("A:A")
   
 If Intersect(Target, rng) Is Nothing Then Exit Sub
 
 [G2:F2].ClearContents
   
myFnd = Target.Value
    'MsgBox myFnd
   
        
Set rngFound = Sheets("Sheet5").Range("A:A").Find(What:=myFnd, _
                                               LookIn:=xlValues, _
                                               LookAt:=xlWhole, _
                                               SearchOrder:=xlByRows, _
                                               SearchDirection:=xlNext, _
                                               MatchCase:=False)
                                               
If Not rngFound Is Nothing Then
Set setRng = rngFound.Offset(, 1).Resize(1, 3)
        
        Msg = "With - " & rngFound & vbCr & "Do you want AVG or STDV." _
                      & vbCr & "AVG = ""Yes""" & vbCr & "STDV = ""No"""
        
        ans = MsgBox(Msg, vbQuestion + vbYesNoCancel)
        
        Select Case ans

            Case vbYes
               ' MsgBox "AVG"
                Range("G2") = myFnd & " Avg " & Application.WorksheetFunction.Average(setRng)

            Case vbNo
                'MsgBox "STDV"
                Range("F2") = myFnd & " STDV " & Application.WorksheetFunction.StDev(setRng)

            Case vbCancel
                MsgBox "Neither-CANCEL"
                Cancel = True
                Exit Sub

          End Select
End If
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,174
Members
449,071
Latest member
cdnMech

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