Hello Everyone
I am trying to use intersect but cant get the code right.
What I have is to rows of data from a1 to m2
row 1 acts as a header row to as the data
I have inherited a program which uses intersect to pick up the information required in the range c1 to m3 using the following code
ValuesFound = Intersect(.Offset(0, 0), .Offset(0, iColLocation))
x = ubound(valuesfound,2)
for g = 1 to x
y1(g) = valuesfound(1,g)
y2(g) = valuesfound(2,g)
next x
usually there is two rows of data and this works fine but occasionally there are three rows of data ( header + two rows of data) . So what I did whas write a small piece of code that averages the two rows of data to the fourth row and deletes the other two rows. This puts it back to the original layout
a a a a a a a a a a a a a (header)
d d 1 1 1 1 1 1 1 1 1 1 1 data
d d 3 3 3 3 3 3 3 3 3 3 3 data
turns into
a a a a a a a a a a a a a (how the data should look)
d d 2 2 2 2 2 2 2 2 2 2 2
The code works fine for the if the data starts off like the second case but as soon as I do my average delete macro the intersect code only picks up one row (a a a a ... ) in the valuesfound and not the second row (2 2 2 2 ...). Which crashes the code later on. What is happening here?
Is there a way of saying
if average code has been run
set range1= row1
set range2=row2
valuesfound= intersect(range1,range2)
if not then
valuesfound= (original method)
Hope this makes sense.
Thanks for any help
Andrew299
It may have hit every branch on its way out of the ugly tree, but hey! It works. (but don't quote me on that)
I am trying to use intersect but cant get the code right.
What I have is to rows of data from a1 to m2
row 1 acts as a header row to as the data
I have inherited a program which uses intersect to pick up the information required in the range c1 to m3 using the following code
ValuesFound = Intersect(.Offset(0, 0), .Offset(0, iColLocation))
x = ubound(valuesfound,2)
for g = 1 to x
y1(g) = valuesfound(1,g)
y2(g) = valuesfound(2,g)
next x
usually there is two rows of data and this works fine but occasionally there are three rows of data ( header + two rows of data) . So what I did whas write a small piece of code that averages the two rows of data to the fourth row and deletes the other two rows. This puts it back to the original layout
a a a a a a a a a a a a a (header)
d d 1 1 1 1 1 1 1 1 1 1 1 data
d d 3 3 3 3 3 3 3 3 3 3 3 data
turns into
a a a a a a a a a a a a a (how the data should look)
d d 2 2 2 2 2 2 2 2 2 2 2
The code works fine for the if the data starts off like the second case but as soon as I do my average delete macro the intersect code only picks up one row (a a a a ... ) in the valuesfound and not the second row (2 2 2 2 ...). Which crashes the code later on. What is happening here?
Is there a way of saying
if average code has been run
set range1= row1
set range2=row2
valuesfound= intersect(range1,range2)
if not then
valuesfound= (original method)
Hope this makes sense.
Thanks for any help
Andrew299
It may have hit every branch on its way out of the ugly tree, but hey! It works. (but don't quote me on that)