Comparison operator query

shumba

Board Regular
Joined
Oct 5, 2010
Messages
168
Hello,​
The procedure below is a loop designed to test a value in the selected range / cell against a value in the same row two columns to the right. If the selected cell’s value is less than the value in the column two to the right and the value in the cell fifteen to the right is greater than that in the cell sixteen to the right of the selected cell then a value in the cell one to the right of the selected cell is copied to another worksheet.​
The part of the statement (underlined) is not doing what it should. If the value in the selected cell is equal to the cell two to the right it is still copying the value ( one to the right of the selected cell) to the other worksheet. It is as if the code is being read as <= instead of <.​
Please will someone show me where I am going wrong.​
Code:
[LEFT][LEFT]Sub Assesment1()

    Sheets("StockAssesment").Select

    Range("g7").Select

    Do Until IsEmpty(Selection)

    If [U]Selection.Value < Selection.Offset(0, 2)[/U].Value And Selection.Offset(0, 15) > Selection.Offset(0, 16) Then _

    Selection.Offset(0, 1).Copy         Destination:=Sheets("StockAssessmentList").Range("b:b").Cells(Rows.Count).End(xlUp).Offset(1, 0)

    Selection.Offset(1, 0).Select

    Loop

End Sub[/LEFT]
[/LEFT]
Any help will be much appreciated.​
Thank you .​
Rob.​
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
If these are numeric values in the cells then be certain that this isn't being caused because your display of the numbers is obscuring their true value (eg they are decimal numbers to n decimal places, but you have formatting applied to only display whole numbers for example).
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,240
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top