Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Swapping Columns | Excel Discussion (Misc queries) | |||
Swapping Rows & Columns | Excel Discussion (Misc queries) | |||
swapping data from 2 separate columns | Excel Discussion (Misc queries) | |||
swapping columns?? | Excel Discussion (Misc queries) | |||
Swapping rows and columns | Excel Worksheet Functions |