View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Array / Looping Question

Matt,

Just some general comments...
Use Option Explicit at the top of each module.
Declare all of your variables - Option Explicit will help with this.
Use a data type declaration of Long for all variables referring to row numbers.

Regards,
Jim Cone
San Francisco, USA


"Matt W" wrote in message
oups.com...
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