Formula - Efficient way to assign signs (+/-) to numbers in alternating in a column

Cubist

Well-known Member
Joined
Oct 5, 2023
Messages
1,801
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I'm looking for an efficient way to turn column A into column B. I have a few ideas but what's the most efficient?
Book1
AB
1FromTo
2+5
352
4+-1
52-8
6-
71
8-
98
Sheet13
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
What ideas did you have?
Maybe
Code:
Sub Concat_Offsets()
Dim lr As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False
   With ActiveSheet
        If .AutoFilterMode Then .AutoFilterMode = False
            With .Range("A1:A" & lr)
                .AutoFilter 1, ">0"
                    With .Range("B2:B" & lr)
                        .Formula = "=R[-1]C[-1]&RC[-1]"
                    End With
            End With
        .AutoFilterMode = False
    End With
    With Range("B2:B" & lr)
        .Value = .Value
        .SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
    End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
I don't know if it is the most efficient, but here is one way using strictly formulas (no VBA).
Formula to put in cell B2 and copy down to cell B5:
Excel Formula:
=VALUE(OFFSET($A$2,(ROW()*2)-4,0) & OFFSET($A$2,(ROW()*2)-3,0))

Results:
1717634802886.png
 
Upvote 0
Thanks for the above suggestions above. I'm looking for a formula instead of VBA.
@Joe4 I have a large range so I'm trying to avoid OFFSET if possible. I've been playing with this for a bit, this is the best I've come up with. I have a feeling there's a more concise way.
Book1
AB
1FromTo
2+5
352
4+-1
52-8
6-
71
8-
98
Sheet4
Cell Formulas
RangeFormula
B2:B5B2=LET(w,WRAPROWS(A2:A9,2),IF(CHOOSECOLS(w,1)="+",1,-1)*CHOOSECOLS(w,2))
Dynamic array formulas.
 
Upvote 0
Here is my take on this:
Excel Formula:
=INDEX(--(A2:A8&A3:A9),SEQUENCE((ROWS(A2:A8)+1)/2,,,2))
 
Upvote 0
@Tetra201 thanks for the idea of offsetting the range. This is what I came up with from that.
Book1
AB
1FromTo
2+5
352
4+-1
52-8
6-
71
8-
98
Sheet4
Cell Formulas
RangeFormula
B2:B5B2=TOCOL(IF(A2:A8="+",1,-1)*A3:A9,2)
Dynamic array formulas.
 
Upvote 0
Why not just
Excel Formula:
=TOCOL(--(A2:A8&A3:A9),2)
;)
That is pretty cool! Why didn't you suggest it the first time around! ;)

I must admit, there are a number of new functions I have not used much of yet, and TOCOL is one of those!
 
Upvote 0

Forum statistics

Threads
1,221,848
Messages
6,162,419
Members
451,765
Latest member
craigvan888

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