Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Swapping columns


I made this little macro this morning which may help someone who visits
this forum :)

I don't know if this is an efficient way of doing this but then again
I'm only a beginner so I have an excuse ;)


Code:
--------------------
Public Sub swopcolumn()

Dim Rownum As Integer
Dim Rowaddr As Integer
Dim Colnum As Integer
Dim Colladdr As Integer
Dim startcol As Integer
Dim startrow As Integer
Dim firstcell As Variant
Dim secondcell As Variant
Dim looprange As Integer


Rownum = Selection.Rows.Count
Rowaddr = Selection.Rows(Rownum).Row
Colnum = Selection.Columns.Count
Colladdr = Selection.Columns(Colnum).Column
startcol = (Colladdr - Colnum) + 1
startrow = (Rowaddr - Rownum) + 1

For looprange = 1 To Rownum

firstcell = Cells(startrow, startcol)
secondcell = Cells(startrow, Colladdr)

Cells(startrow, startcol) = secondcell
Cells(startrow, Colladdr) = firstcell

startrow = startrow + 1


Next

End Sub
--------------------


This swops the data between the end columns of a selected range.


--
Daminc
------------------------------------------------------------------------
Daminc's Profile: http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=526713

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Swapping Columns mePenny Excel Discussion (Misc queries) 3 April 22nd 09 09:25 PM
Swapping Rows & Columns Alan Excel Discussion (Misc queries) 2 August 14th 08 08:38 PM
swapping data from 2 separate columns Johnny D Excel Discussion (Misc queries) 1 February 15th 06 08:09 PM
swapping columns?? Johnny D Excel Discussion (Misc queries) 0 February 15th 06 07:13 PM
Swapping rows and columns Dorn Excel Worksheet Functions 2 November 11th 05 09:07 PM


All times are GMT +1. The time now is 04:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"