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


What would be the best way, in code, to swap entire lines 19 and 20
in sheet1 ?

Thanks - Kirk
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Swap 2 lines

Hi,

Right click your sheet tab, view code and paste this in and run it

Sub Sonic()
Rows(20).Insert Shift:=xlDown
Cells(19, 1).EntireRow.Copy Destination:=Cells(20, 1)
Cells(21, 1).EntireRow.Copy Destination:=Cells(19, 1)
Rows(21).EntireRow.Delete
End Sub

Mike

"kirkm" wrote:


What would be the best way, in code, to swap entire lines 19 and 20
in sheet1 ?

Thanks - Kirk

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Swap 2 lines

Hi
Select the two row number headings and run this

Sub swaprow()
Dim Row1 As Range, Row2 As Range
Dim Temp1 As Variant, Temp2 As Variant
Set Row1 = Selection.Areas(1)
Set Row2 = Selection.Areas(2)
Temp1 = Row1.Value
Temp2 = Row2.Value
Row1.Value = Temp2
Row2.Value = Temp1
Set Row1 = Nothing
Set Row2 = Nothing
End Sub

regards
Paul

On Mar 13, 8:02*am, kirkm wrote:
What would be the best way, in code, *to swap entire *lines 19 and 20
in sheet1 ?

Thanks - Kirk


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Swap 2 lines

Sub Short()
Rows("19:19").Cut
Rows("21:21").Insert Shift:=xlDown
End Sub

"kirkm" wrote:


What would be the best way, in code, to swap entire lines 19 and 20
in sheet1 ?

Thanks - Kirk

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default Swap 2 lines

Thanks very much everyone!

Interesting to see the different methods and
mission accomplished this end !

Cheers - Kirk
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
swap Gary Excel Worksheet Functions 9 August 2nd 06 03:51 AM
Swap the X and Y axes LAUR Charts and Charting in Excel 1 May 15th 06 07:21 PM
swap axes Fridgemaster Charts and Charting in Excel 3 March 30th 06 02:22 PM
Swap Cells William Wolfe Excel Discussion (Misc queries) 4 June 16th 05 05:18 PM
Last, First Name Swap LaramieHartmann Excel Programming 1 December 9th 03 03:50 PM


All times are GMT +1. The time now is 03:15 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"