If Then with an and an or

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
439
Office Version
  1. 2019
Platform
  1. Windows
Thanks in advance for any suggestions for which feedback will be given.

Why is the following VBA Code actually bolding the cell and filling it in red when the cell is 1 or 3 for column 13? It is meant to say if j = 13 and if the value of the cell is not 1 or 3, then make it bold and fill it red, but it's doing the opposite.

Code:
For j = 1 to 41
           
            If j = 20 Or j = 21 Or j = 22 Or j = 23 Or j = 31 _
            Or j = 32 Or j = 34 Or j = 35 Or j = 36 Or j = 37 _
            Or j = 39 Or j = 40 Then
            'do nothing

            ElseIf j = 13 Then
                If Cells(i, j) <> 1 Or Cells(i, j) <> 3 Then
                    Cells(i, j).Font.Bold = True
                    Cells(i, j).Interior.ColorIndex = 3
          End If

          End If

Next j
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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