single if statement to replace multi?

Nuclear_Dude

New Member
Joined
Jun 13, 2011
Messages
4
I have the following data:
__24__|__48___|__120__|__125__|__208__|__240__|__250__| ...
_true | true_ | false | false | false | false | false | ...
false | false | _true | false | _true | false | false | ...
false | false | _true | false | false | _true | false | ...
false | false | false | _true | false | false | _true | ...
false | false | false | _true | false | false | false | ...
__.___|___.___|___.___|___.___|___.___|___.___|___.___| ...
__.___|___.___|___.___|___.___|___.___|___.___|___.___| ...
__.___|___.___|___.___|___.___|___.___|___.___|___.___| ...


you may have noticed that these are common voltages.
What I need is to condense the information into a single column, that reads "120" if it is a single voltage, but "120/208" or maybe "120/240", but if more than two columns are true or NO columns are true (both are possible, but not shown above), I need it to show FALSE, or ERROR, or whatever.

One way to accomplish this is with IF statement nesting, but I have 12 different voltage combinations, so that is a REALLY long if statement, and it would need a countif at the beginning to make sure there is at least one true, but not more than two. What I need done is the following:
For(A2:L2, if(cell)=true, output=output+"cell"$1)
so the first run would be in cell A2:
if(A2=true), output=output+A1+"/";
if(B2=true), output=output+B1+"/";
if(C2=true), ...
and the final output would be in the form of "###/###" or "###" or an error if there is no true or if there is more than 2 trues.

Thanks, and please let me know if you need clarification on the question. Below is my current, extremely unelegant solution:
-------
M2 = if(or(countif(A2:L2,TRUE)=1,countif(A2:L2,TRUE)=2),
if(A2,M2&$A$1,...
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I am NOT very good which formulas..

So, here is a vba code.

Before this macro,
in a column N, you should input
"=countif(A2:L2, TRUE)"
This formula should give you number of occurrences of TRUE in A2:L2.
If you've confirmed the formula is correct, copy down.
Code:
Sub getFinalOutput()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Dim i As Long, j As Long
 
 
    For i = 1 To Range("A" & Rows.count).End(xlUp).Row
        For j = 1 To 12
            If Cells(14, i).Value = 2 And Cells(j, i).Value = True Then
                Cells(13, i).Value = Cells(j, i).Value & "&"
                Cells(14, i).Value = 1
            ElseIf Cells(14, i).Value = 1 And Cells(j, i).Value = True Then
                Cells(13, i).Value = Cells(13, i).Value & Cells(j, i).Value
            Else
                Cells(13, i).Value = "ERROR"
            End If
        Next j
    Next i
 
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub

To use this code, right click on the worksheet you're working with and click "View Code"
Copy + Paste the code onto the editor and hit F5 to run the macro.
 
Upvote 0
This is still a bit of a mouthful but see if it does what you want.

Excel Workbook
ABCDEFGHIJKLM
12448120125208240250
2TRUETRUEFALSEFALSEFALSEFALSEFALSE24/48
3TRUEFALSETRUEFALSETRUEFALSEFALSEError
4FALSEFALSETRUEFALSEFALSETRUEFALSE120/240
5FALSEFALSEFALSEFALSEFALSEFALSEFALSEError
6FALSEFALSEFALSETRUEFALSEFALSEFALSE125
Voltages
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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