View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Matt W[_2_] Matt W[_2_] is offline
external usenet poster
 
Posts: 4
Default Array / Looping Question

Wow!

Thank you all so much for your help. I have a functioning macro as
follows, it isn't pretty but it works - pasted below. What I was
trying to do was select find the value in column 3 corresponding to a
value of 30 in the second column - basically a stepwise linear
interpolation. The part that had me stuck was making sure that I was
able to capture all data in cols 2 and 3 that had a matching col1.
This works but if anyone has comments that would be much appreciated.

Thanks all

Sub Get_Grain_Size(gsize As Integer, gsizecol As Integer)
Dim c As Object
Dim rng As Range
Dim counter As Integer
Dim rowcnt As Integer
Dim bnds As Object
counter = 1
rowcnt = -1

Range("A2:A10000").Select
For Each c In Selection
If c.Value = c.Offset(1, 0).Value Then
counter = counter + 1
rowcnt = rowcnt + 1


ElseIf c.Value < c.Offset(1, 0).Value And c.Value =
c.Offset(-1, 0).Value Then

counter = counter + 1
rowcnt = rowcnt + 1

dat = "B" & counter - rowcnt & ":C" & counter
Set bnds = Range(dat)
D = stepwiseinterp(gsize, bnds, 2)
Worksheets("DataReduction").Cells(counter - rowcnt, gsizecol) =
D
rowcnt = -1


Else
counter = counter + 1
End If

Next c
End Sub