• Home
  • Blog
  • Resume
  • Contact
  • Projects
  • Gallery
  • Amit’s Resume
  • About Nagpur
KEEP IN TOUCH

Flip row or column

Mar30
2005
3 Comments Written by admin

To flip the given row as shown in this figure, use the following macro

Flip row or column

Result row

Flip row or column

You can use the same macro for flipping columns too, code will find if it’s a row or a column.

Note: This code was modified on 07/26/07 for error checking, and removal of Option Base

Sub flip()

Dim Arr As Variant
Dim myrange As Range
Dim vSplitedArr As Variant
Dim arRetArr() As Variant, lArrBnd As Long, i As Long

On Error GoTo flip_Error

Set myrange = Range(Selection.Address)
Arr = myrange ‘store the selected values in an array

‘split the selected cells address to an array
vSplitedArr = Split(Selection.Address, “$”)

‘ check if Column names are same
If vSplitedArr(1) = vSplitedArr(3) Then
lArrBnd = UBound(Arr, 1)
ReDim arRetArr(lArrBnd, 0)
For i = 0 To lArrBnd – 1
‘flip the array
arRetArr(i, 0) = Arr(lArrBnd – i, 1)
Next i
Range(Selection.Address) = arRetArr
‘check if Row numbers are same
ElseIf Replace(vSplitedArr(2), “:”, “”) = vSplitedArr(4) Then
lArrBnd = UBound(Arr, 2)
ReDim arRetArr(0, lArrBnd)
For i = 0 To lArrBnd – 1
‘flip the array
arRetArr(0, i) = Arr(1, lArrBnd – i)
Next i
Range(Selection.Address) = arRetArr
Else
MsgBox “Your selection contains multiple rows or columns.” & vbCrLf & _
“This macro will only work on either one column or one row”, vbCritical, “Flip Error”
End If

On Error GoTo 0
SmoothExit_flip:
Exit Sub

flip_Error:
MsgBox “Error ” & Err.Number & ” (” & Err.Description & “) in procedure flip”
Resume SmoothExit_flip
End Sub

Related posts:

  1. Description of the limitations for working with arrays in Excel 2000, Excel 2002, and Excel 2003
  2. Importing IE bookmark
  3. Save HTML files from one folder to Excel files in another folder
Posted in Uncategorized - Tagged cells, excel, flip, VBA
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« Description of the limitations for working with arrays in Excel 2000, Excel 2002, and Excel 2003
» Find the last filled column

3 Comments

  1. Anonymous's Gravatar Anonymous
    April 24, 2007 at 5:10 pm | Permalink

    Thank you for posting this. It works great.
    -Sal

  2. Blazio's Gravatar Blazio
    May 17, 2007 at 1:21 pm | Permalink

    is there any way to have this macro work on a mac? thanks!

  3. Anonymous's Gravatar Anonymous
    February 17, 2008 at 8:34 pm | Permalink

    Very, very nice to have one macro that can figure out how to flip a column or row. Great job!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Tags

Access Alt F8 Books boxplot cells charts count cursor dashboard data mining dbase design error excel excel functions export filter flip LaTex MS query Number Err ODBC pipes Press Alt F11 Public Sub python R random numbers Range Cells report scripting software sparklines SQL SQL server stack columns statistics stemming string tag cloud text mining UDF VBA visualization wildcard

Network

View Ashutosh Nandeshwar's profile on LinkedIn

Recent Comments

  • larry on Access Export to Excel (2007)
  • Betty Chou on Projects
  • Rwill on Access Export to Excel (2007)
  • Bharathi on The search key was not found in any record in Access
  • Michael on The search key was not found in any record in Access

Related Posts

  1. Description of the limitations for working with arrays in Excel 2000, Excel 2002, and Excel 2003
  2. Importing IE bookmark
  3. Save HTML files from one folder to Excel files in another folder

EvoLve theme by Blogatize  •  Powered by WordPress nandeshwar.info