Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

>= not working properly

Status
Not open for further replies.

turtlejack

Technical User
Jan 25, 2005
26
US
I am trying to copy certain cells from one worksheet to another.on the first much of the data in the column to be copied, is duplicate. on the page I am trying to copy to, I only want one instance of each bit of data.
in the following code, I stepped into the code, and it is copying data that is equal to data on the previous row. and it should not be.


Sub locate()
Dim main As Worksheet
Dim locate_request As Worksheet

c = 20
v = 6
p = 3
Set main = Worksheets("main")
Set locaterequest = Worksheets("locate request")




For v = v To c

If main.Range("b" & v) >= locaterequest.Range("a" & (v - 1)) Then
main.Range("b" & v).Copy locaterequest.Range("a" & p)
p = p + 1



End If
Next v
End If




End Sub
 
For starters:

For v = v To c

is horrible notation - you should not use the same definition for a constant AND a variable. It would be much better to use

For i = v to c

As to the actual question:
it is copying data that is equal to data on the previous row
well you are using >= which means that if 1 thing is greater than OR EQUAL TO another, the test will be true. To only run when 1 is bigger than another, you must use > NOT >=

Rgds, Geoff

"Three things are certain: Death, taxes and lost data. Guess which has occurred"

Please read FAQ222-2244 before you ask a question
 
You want > instead of >= ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
thank you soo much.. I just came back to repost, I found my error(completely embarassed) to find you had replied.. thank you soo much.. I knew it had to be something simple. I wish I had gotten back to repost before anyone seen my mistake. *sigh* oh well...
thank you soo much anyways.
 
that would be "Does not equal" <criteria> or more literally "Anything greater than or less than" <criteria>

Rgds, Geoff

"Three things are certain: Death, taxes and lost data. Guess which has occurred"

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top