Extract Odds from the range

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,362
Office Version
  1. 2010
Using Excel 2010
Hello,

I have a 5 number in columns D:H I want a formula or a macro which can Extract odd numbers from 1 To 25 in Columns J:N and Extract odd numbers from 26 To 50 in Columns P:T

Note: I want a formula or a macro which can be used in Excel 2000 also.

Here is a example sheet with expected results…

Odds.xls
ABCDEFGHIJKLMNOPQRSTU
1
2
3
4n1n2n3n4n5EMOdd 1 To 25EMOdd 26 To 50
5n1n2n3n4n5EMn1n2n3n4n5EMn1n2n3n4n5
616293236412941
77133947507133947
81418193137193137
9473337397333739
1015242844471547
113336374245333745
123410234332343
1327313547492731354749
141410192311923
1514152835401535
16610214549214549
175616232752327
1815162136381521
19132132391321
2015293739491529373949
2117917231791723
22
Sheet1


Regards,
Moti
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Place this formula in J6 and then copy it across to N6. Next select J6:N6 and copy down to row 21:
=IF(AND(MOD(D6,2)=1,AND(D6>=1,D6<=25)),D6,"")

Place this formula in P6 and then copy it across to T6. Next select P6:T6 and copy down to row 21:
=IF(AND(MOD(D6,2)=1,AND(D6>=26,D6<=50)),D6,"")
 
Upvote 0
Hello mumps, yes your formula worked for both the version fine, does it is possible to get result as #post1 combined without spacing.

I appreciate your kind help.

Odds.xls
ABCDEFGHIJKLMNOPQRSTU
1
2
3
4n1n2n3n4n5EMOdd 1 To 25EMOdd 26 To 50
5n1n2n3n4n5EMn1n2n3n4n5EMn1n2n3n4n5
61629323641      29  41
7713394750713     3947 
81418193137  19     3137
947333739 7     333739
10152428444715        47
113336374245     33 37 45
12341023433  23     43
132731354749     2731354749
14141019231  1923     
151415283540 15      35 
16610214549  21     4549
17561623275  23     27
18151621363815 21       
19132132391321      39
20152937394915     29373949
2117917231791723     
22
Sheet1
Cell Formulas
RangeFormula
J6:N21J6=IF(AND(MOD(D6,2)=1,AND(D6>=1,D6<=25)),D6,"")
P6:T21P6=IF(AND(MOD(D6,2)=1,AND(D6>=26,D6<=50)),D6,"")


Good Luck

Kind Regards,

Moti
 
Upvote 0
I don't think that I can do that with a formula. I would probably need a macro.
 
Upvote 0
I don't think that I can do that with a formula. I would probably need a macro.
Hello mumps, thank you for the replay if so can you build a macro that will be great.

I appreciate your kind help.

Good Luck

Kind Regards,

Moti
 
Upvote 0
Try:
VBA Code:
Sub ExtractOdds()
    Application.ScreenUpdating = False
    Dim v As Variant, r As Long, c As Long, x As Long, y As Long
    x = 10: y = 16
    v = Range("D6", Range("D" & Rows.Count).End(xlUp)).Resize(, 5).Value
    For r = LBound(v) To UBound(v, 1)
        For c = LBound(v) To UBound(v, 2)
            If v(r, c) Mod 2 = 1 And v(r, c) >= 1 And v(r, c) <= 25 Then
                Cells(r + 5, x) = v(r, c)
                x = x + 1
            ElseIf v(r, c) Mod 2 = 1 And v(r, c) >= 26 And v(r, c) <= 50 Then
                Cells(r + 5, y) = v(r, c)
                y = y + 1
            End If
        Next c
        x = 10: y = 16
    Next r
    Application.ScreenUpdating = True
End Sub
 
Upvote 1
Solution
Try:
VBA Code:
Sub ExtractOdds()
    Application.ScreenUpdating = False
    Dim v As Variant, r As Long, c As Long, x As Long, y As Long
    x = 10: y = 16
    v = Range("D6", Range("D" & Rows.Count).End(xlUp)).Resize(, 5).Value
    For r = LBound(v) To UBound(v, 1)
        For c = LBound(v) To UBound(v, 2)
            If v(r, c) Mod 2 = 1 And v(r, c) >= 1 And v(r, c) <= 25 Then
                Cells(r + 5, x) = v(r, c)
                x = x + 1
            ElseIf v(r, c) Mod 2 = 1 And v(r, c) >= 26 And v(r, c) <= 50 Then
                Cells(r + 5, y) = v(r, c)
                y = y + 1
            End If
        Next c
        x = 10: y = 16
    Next r
    Application.ScreenUpdating = True
End Sub
Wow mumps, macro worked fantastic and got the expected result as requested. Thank you so much for your kind help and time you spent for giving a perfect solution for my query. 👌

Good Luck!

Kind Regards,:)
Moti
 
Upvote 0

Forum statistics

Threads
1,215,156
Messages
6,123,339
Members
449,098
Latest member
thnirmitha

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