Skip to content

Instantly share code, notes, and snippets.

@0xLeon
Created June 15, 2020 10:24
Embed
What would you like to do?
Excel - Flip Rows / Columns
Sub FlipRows()
Dim vTop As Variant
Dim vEnd As Variant
Dim iStart As Integer
Dim iEnd As Integer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
iStart = 1
iEnd = Selection.Rows.Count
Do While iStart < iEnd
vTop = Selection.Rows(iStart)
vEnd = Selection.Rows(iEnd)
Selection.Rows(iEnd) = vTop
Selection.Rows(iStart) = vEnd
iStart = iStart + 1
iEnd = iEnd - 1
Loop
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Sub FlipColumns()
Dim vTop As Variant
Dim vEnd As Variant
Dim iStart As Integer
Dim iEnd As Integer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
iStart = 1
iEnd = Selection.Rows.Count
Do While iStart < iEnd
vTop = Selection.Columns(iStart)
vEnd = Selection.Columns(iEnd)
Selection.Rows(iEnd) = vTop
Selection.Rows(iStart) = vEnd
iStart = iStart + 1
iEnd = iEnd - 1
Loop
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment