Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This should do what you want based on your description. It assumes that
your values are in columns A and B on the active sheet, and the total is then written to cell C1. GetTotal() prompts for the distance and passes it to the function TotalShorter(), which returns the total. You could make it more flexible by assigning range names ("X" and "Y"), or by adding prompting for the ranges (either addresses or rows and columns). Option Explicit Sub GetTotal() Dim d As Single Do d = Application.InputBox(Prompt:="Enter a value between 0 and 10:", Type:=1) Loop While d < 0 Or d 10 If d = False Then Exit Sub Else Cells(1, 3).Value = TotalShorter(d) End If End Sub Function TotalShorter(distance As Single) As Integer Dim X As Variant, Y As Variant Dim z As Single Dim i As Integer, total As Integer ' read the x and y ranges into the variants X = Range(Cells(2, 1), Cells(11, 1)) Y = Range(Cells(2, 2), Cells(11, 2)) For i = 1 To UBound(X) z = (X(i, 1) ^ 2 + Y(i, 1) ^ 2) ^ 0.5 If z <= distance Then total = total + 1 End If Next i TotalShorter = total End Function Gary |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Reading Data from another workbook... depending on variable in a cell? | Excel Discussion (Misc queries) | |||
Reading more than one set of data from a single cell | Excel Programming | |||
reading data from com port into 2 different cell locations. | Excel Programming | |||
Reading Entire Range | Excel Programming | |||
Reading a Range | Excel Programming |