VBA to identify negative odd numbers

maeitea

New Member
Joined
Nov 19, 2018
Messages
2
Hi,

I have a table with cells that contain different numbers and have different color backgrounds. I need to get vba to identify all the odd numbers that have a red background. Then I need it to write down the numbers starting from a cell I called ''tulem''. This is what I have so far, it writes down all the red backgrounded numbers that are odd but for some reason it doesn't include negative numbers that also have a red background. How do I get it to include negative numbers aswell? Thank you.

Code:
Sub arvuta()Dim row, column, t, a, n


Set t = Range("Tulem")
Sheets("Andmed").Select
row = 9
column = 2
a = 1
n = 0
Do Until column = 12
    row= 9
    Do Until row = 29
        n = cells(row, column).Value
        If cells(row, column).Interior.ColorIndex = 3 Then
            If Int(cells(row, column).Value) Mod 2 = 1 Then
                t.cells(a, 1) = cells(row, column)
                  a = a + 1
        
            End If
        End If
    row = row + 1
    Loop
column = column + 1
Loop




End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Maybe this;
Code:
If Int(cells(row, column).Value) Mod 2 = 1 or Int(cells(row, column).Value) Mod 2 = -1 Then
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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