how to write macro that filters odd & even numbered data ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Could anyone please help me to write a macro that filters odd & even numbered
IPAddress from a huge list fo data.

Thanks & Regards
 
I don't know if you have Text or Numbers, the following will work for either:

The follow formula provides True for Even numbers
=TRUNC(RIGHT(A1)/2)*2=RIGHT(A1)+0

The following formula provides True for Odd numbers
= NOT(TRUNC(RIGHT(A1)/2)*2=RIGHT(A1)+0)

You can read about filtering at
http://www.contextures.com/tiptech.html

The easiest way is to use a helper column, put either formula into Column B
then Select Column B (cell B1 active cell), Data, Filter, Auto Filter
on the arrow drop down choose True or choose False

You can copy the cells and paste elsewhere because a filtered list exposes
on those that make it through the filter, or you can print the list. .
 
try this sub (may not be elegant)


your data is in A1 downwards
the sub is

Public Sub test()
Dim myrange As Range
Dim cell As Range
Dim reminder As Single
Dim divisor As Single
Set myrange = Range(Range("a1"), Range("a1").End(xlDown))
For Each cell In myrange
divisor = cell / 2
divisor = Int(divisor)
reminder = cell - divisor * 2
If reminder = 0 Then
cell.Offset(0, 1) = cell
Else
cell.Offset(0, 2) = cell
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top