Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default reading data from a range into a cell


i have a range of data (points on a 10 X 10 grid) that i need to read
into a cell...

i posted a thread a bit ago but was unclear as to what it is I actually
need help with

my range of data consists of 2 cloumns by 10 rows (10 data points)

example

_x__y_
2 3
1 2
3 5
4 5
.. .
.. .
.. .
.. .
7 7

the target cell will be a basic count program that counts how many of
the 10 data points are within a certain distance from the target cell

my thoughts are

(target cell - origin of 10 X 10 grid)

i = 1 (1st out of 10 data points)
count = 0
if distance from target cell to data point (i=1) <= radius then, count
= count +1, else count = count
next i (until 10 data points are all read)

my programming is very rusty but i am trying to get a count of how many
of the ten data points (i= 1 thru 10) are within the specified distance
from the target cell (target cells are grid points)

for example if 4 of the 10 data points are within a certain distance,
the target cell should display "4"

any help would be greatly appreciated


--
brya6347
------------------------------------------------------------------------
brya6347's Profile: http://www.excelforum.com/member.php...o&userid=20024
View this thread: http://www.excelforum.com/showthread...hreadid=346120

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default reading data from a range into a cell

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading Data from another workbook... depending on variable in a cell? Rob Moyle Excel Discussion (Misc queries) 4 March 13th 06 04:21 PM
Reading more than one set of data from a single cell Broadsider Excel Programming 2 November 14th 04 09:50 PM
reading data from com port into 2 different cell locations. Neil K Excel Programming 0 September 30th 04 12:26 PM
Reading Entire Range Peter[_46_] Excel Programming 1 September 17th 04 04:20 PM
Reading a Range Pablo Excel Programming 2 June 4th 04 02:59 PM


All times are GMT +1. The time now is 06:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"