Reputation: 565
I have the below example where I have 3 columns in "CONDITION"
If I have data in all the 3 columns then the results should be column2 and column3 as shown in fig.
I used the below formula for "Results with my formula"
=IF(AND(NOT(ISBLANK($A2));NOT(ISBLANK( $B2));NOT(ISBLANK( $C2)));CONCATENATE( $B2; $C2)
But, I need the results as in "Expected Results" column
In case if the value in the above row is empty then the current value has to be posted in this cell.
Upvotes: 0
Views: 480
Reputation: 187
Assuming that you start on row 2, this macro should do the trick.
Sub Test()
Dim a as Long
Dim b as Long
Dim lastrow as Long
lastrow = Cells(Rows.Count, 2).End(xlUp).Row
b = 2
For a = 2 To lastrow
If Cells(a, 1) <> "" Then
Cells(b, 7) = Cells(a, 2) & " " & Cells(a, 3)
b = b + 1
End If
Next
End Sub
Upvotes: 2
Reputation: 3802
Another formula solution.
Formula in E2, copied down :
=IFERROR(INDEX($B$2:$B$13&" "&$C$2:$C$13,AGGREGATE(15,6,ROW($A$2:$A$13)-ROW($A$1)/($A$2:$A$13<>""),ROW(A1))),"")
Note : please change from "," to ";" in suit with your own country regional settings.
Upvotes: 1
Reputation: 152450
NOTE: My local settings use ,
instead of ;
for the formula criteria delimiter. You may need to switch out the ,
for ;
If one has the dynamic array formula FILTER:
=FILTER(B3:B14&" "&C3:C14,LEN(A3:A14)*LEN(B3:B14)*LEN(C3:C14)>0)
If not then use:
=INDEX(B:B,AGGREGATE(15,7,ROW($B$3:$B$14)/(LEN($A$3:$A$14)*LEN($B$3:$B$14)*LEN($C$3:$C$14)>0),ROW($ZZ1)))&" "&INDEX(C:C,AGGREGATE(15,7,ROW($B$3:$B$14)/(LEN($A$3:$A$14)*LEN($B$3:$B$14)*LEN($C$3:$C$14)>0),ROW($ZZ1)))
put in first cell and copy down.
Upvotes: 2