Compare Cell against previous cell

GRE86

New Member
Joined
Feb 12, 2015
Messages
2
Hi all, need some help.

I have a list of depths within one column ("I"), the top of that column (I12) contains the word "depth". I need a script that will compare the 2nd depth (I14) to the 1st (I13) to make sure its deeper (larger value), then 3rd (I15) to 2nd (I14), 4th (I16) to 3rd (I15), 5th (I17) to 4th (I16) and so on. Basically a script that will make sure the previous value is less than the next value.

I also need the script to:

Ignore the depth row (I12)
ignore blanks (after the last data point)
and this is not a static list, the length of the list can vary depend on number of data points.

I have used the color scale conditional formatting but the colour changes are too acute to recognise. I also =OFFSET(INDIRECT(ADDRESS(ROW(), COLUMN())),-1,0) but this will attempted to compare the first depth point to the word "depth" and also the last data point to a blank cell.

any help would be appreciated
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Update:

Managed to get it to work with conditional formatting but would prefer the error message prompt. So far i have:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
For I = 13 To 999
If Cells(I, "I") > Cells(I + 1, "I") Then
x = 1
Cells(I, "I").Select
Exit For
End If
Next I


If x = 1 Then MsgBox "Error"


End Sub

Unfortunately, this script is giving an error messages as the last value in the list is greater than the blank cell below it, any improvements would be appreciated
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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