Skip to content

Instantly share code, notes, and snippets.

@simonbromberg
Created May 26, 2016 16:12
Show Gist options
  • Save simonbromberg/b802fce556b56d0ba5f7a8143c42369e to your computer and use it in GitHub Desktop.
Save simonbromberg/b802fce556b56d0ba5f7a8143c42369e to your computer and use it in GitHub Desktop.
'a simple, (and pretty inefficient, but easy) macro to flip the values in a horizontal or vertical range. Saves a lot of time when you just want to swap two values or flip a list.
Sub flipRange()
'
' flipRange Macro
'
'
Dim i As Long
Dim num As Long
Dim newRange As Range
Dim rng As Range
Dim formulas() As String
i = 1
num = Selection.Cells.count
ReDim formulas(1 To num)
For Each rng In Selection
formulas(i) = rng.Formula
i = i + 1
Next rng
i = num
For Each rng In Selection
rng.Formula = formulas(i)
i = i - 1
Next rng
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment