Macro to flip horizontal cells to vertical and keep formulas

Jarke

Board Regular
Joined
Aug 13, 2016
Messages
95
Hi,

I'm looking for a macro to flip horizontal cells to vertical that also keeps the formulas. Does anyone have one in store?

Could be basic, and start in active sheet in A1 etc.

Thanks in advance!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You could try:
Code:
Range("A1:E1").Copy
Range("A2").PasteSpecial xlPasteAll, Transpose:=True
You would need to substitute your actual range and destnation anchor cell.
 
Upvote 0
Hi mate, thanks. But it does not lock the formulas. My goal is that the formulas in horizontal will be the same when it's turned into vertical alignment. Any idéas for that?
 
Upvote 0
Try this, if it works for you


Code:
Sub Transposewithformula()
    Cells.Replace What:="=", Replacement:="#=", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    
    Range("A1:E1").Copy
            
    Range("A2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
    
    Application.CutCopyMode = False
    
    Cells.Replace What:="#=", Replacement:="=", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
 
Upvote 0
Thank you for your reply! Yes something like that. I noticed a problem tho, I need to keep the formulas in arrays "{ }", would you know how to add that to the VBA formula?
 
Upvote 0
Try this one. Second part will keep formula in { }.

Code:
Sub Transposewithformula()
    
    Dim fArray As Variant
    Dim Rng As Range
    
    
    Cells.Replace What:="=", Replacement:="#=", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    
    Range("A1:E1").Copy
            
    Range("A2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
    
    Application.CutCopyMode = False
    
    Cells.Replace What:="#=", Replacement:="=", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

With Sheet1
    fArray = .Range("A2:A6").FormulaR1C1
    Set Rng = .Range("A2:A6")
    Rng.Formula = fArray
    Rng.FormulaArray = Rng.FormulaR1C1
End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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