Multiple TRUE conditions

cr2289

New Member
Joined
Jul 21, 2016
Messages
26
Office Version
  1. 365
Platform
  1. Windows
I'm trying to create a macro and formula that will work with multiple true conditions. In column I there are numbers, about 40. In column J, I'd like to convert those numbers to text. Some numbers will be AA (true) and others BB (false). I tried over and over to get the formula to work and kept running into missing closing parenthesis errors. The formula below was finally accepted, but alas, it won't copy down to the rest of the cells in the column. What am I doing wrong? Here's the formula I used cell J7:

=IF(OR(I7=9, OR(I7=13,OR(I7=25,OR(I7=26,OR(I7=38,OR(I7=39,OR(I7=40,OR(I7=50,OR(I7=51,OR(I7=56)))))))))),"AA","BB").

The formula work in cell J7 but it won't copy down to the cells below. The value in J8 is also 38. I only included the true numbers. The numbers not included in the true conditions are false (BB). I don't think I need to list them individually, or do I?

Also, how do I create macro language that will include this formula in cell J7 down to the last active row?

Thanks so much for your help.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
=IF(OR(I7=9, OR(I7=13,OR(I7=25,OR(I7=26,OR(I7=38,OR(I7=39,OR(I7=40,OR(I7=50,OR(I7=51,OR(I7=56)))))))))),"AA","BB").
I think you may be able to simplify this formula greatly. If I am understanding it correctly, there is no need to nest the IF statements (you just aren't using OR correctly).
Try this:
Excel Formula:
=IF(OR(I7=9,I7=13,I7=25,I7=26,I7=38,I7=39,I7=40,I7=50,I7=51,I7=56),"AA","BB")
 
Upvote 0
Try this:
I included the values you mentioned modify by adding more if needed.
Looks down Column I till last value.
Starts in Range("I7")
VBA Code:
Sub Select_Case_Me()
'Modified  7/26/2022  8:31:51 PM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "I").End(xlUp).Row

For i = 7 To Lastrow
    Select Case Cells(i, "I").Value
        Case 9, 13, 25, 26, 38, 39, 40, 50, 51, 56
            Cells(i, "J").Value = "AA"
            Case Else: Cells(i, "J").Value = "BB"
            End Select

Next
MsgBox "Done"
Application.ScreenUpdating = True
End Sub
 
Upvote 0
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

The formula work in cell J7 but it won't copy down to the cells below.
Your formula copies down fine for me, however Joe has shortened it somewhat and you can shorten it even further as follows.
Excel Formula:
=IF(OR(I7={9,13,25,26,38,39,40,50,51,56}),"AA","BB")

how do I create macro language that will include this formula in cell J7 down to the last active row?
I would do it like this.
VBA Code:
Sub Insert_Formula()
  Range("J7:J" & Range("I" & Rows.Count).End(xlUp).Row).Formula = "=IF(OR(I7={9,13,25,26,38,39,40,50,51,56}),""AA"",""BB"")"
End Sub
 
Upvote 0
I would think I would like the values entered into the cells and not the formulas.
But:
 
Upvote 0
Try this:
I included the values you mentioned modify by adding more if needed.
Looks down Column I till last value.
Starts in Range("I7")
VBA Code:
Sub Select_Case_Me()
'Modified  7/26/2022  8:31:51 PM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "I").End(xlUp).Row

For i = 7 To Lastrow
    Select Case Cells(i, "I").Value
        Case 9, 13, 25, 26, 38, 39, 40, 50, 51, 56
            Cells(i, "J").Value = "AA"
            Case Else: Cells(i, "J").Value = "BB"
            End Select

Next
MsgBox "Done"
Application.ScreenUpdating = True
End Sub
Thank you!!!
 
Upvote 0
Thank you!!!
It sounds then like you wanted the values placed in column J, not formulas as you asked for. ;)
how do I create macro language that will include this formula in cell J7 down to the last active row?
You are quite welcome to continue with the row-by-row looping to insert the values but if you want, you can process the whole column together. One way would be

VBA Code:
Sub Insert_Values()
  Const myNums As String = "9,13,25,26,38,39,40,50,51,56"
  
  With Range("J7:J" & Range("I" & Rows.Count).End(xlUp).Row)
    .Formula = "=if(or(I7={" & myNums & "}),""AA"",""BB"")"
    .Value = .Value
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

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