Write Macro to sort data based on change between rows

eulerddx4

New Member
Joined
Jul 27, 2014
Messages
16
I have a macro written that sifts through the active column and ignores data that is greater than 18 and less than or equal to 0. In addition to this I would like to sift through the column to the left of the active cell and skip over data where the absolute value of the difference between the next row and the current row is greater than 0.2. Basically I don't want any change greater than 0.2. I have very limited experience and could use help figuring this out. I have posted the working macro below:

Sub mypicker()
rownow=activecell.row
columnnow=activecolumn.column
newrow=9
newcolumn=1
mytime=0
While Cells(rownow,columnnow).Value <> ""
If Cells (rownow,columnnow).Value >18 or (rownow,columnnow).Value <=0 Then
mya=myb
Else
Cells(newrow,newcolumn).Value = mytime
Cells(newrow,newcolumn+1).Value = Cells(rownow,columnnow-1).Value
Cells(newrow,newcolumn+4).Value = Cells(rownow,column now).Value
newrow=newrow+1
End If
rownow=rownow+1
mytime=mytime+1
Wend
End Sub

I tried to put the following code before then on the first if statement but had no luck. Your help is greatly appreciated:
Or Abs(Cells(rownow-1,columnnow+1)-Cells(rownow-1,columnnow)>0.2)
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
This statement
Or Abs(Cells(rownow-1,columnnow+1)
looks to the cell above and to the right of the current cell and this one
Cells(rownow-1,columnnow)
is looking at the cell directly above the current cell. From your description, that does not seem like what you are trying to do. I would think it would be more along the lines of:
Code:
Abs(Cells(rownow+1,columnnow-1)-Cells(rownow,columnnow-1)>0.2)

So, if you were currently in cell B3, it would be A4 - A3. Is that what you are trying to achieve?
 
Upvote 0
Wow, I can't believe I missed that but you wrote exactly what I want to do. Thank you very much for your help!!
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,792
Members
449,468
Latest member
AGreen17

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