#1   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default how to switch rows

Is there a quick way to switch the contents of two rows ?

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson
 
Posts: n/a
Default how to switch rows

You can do it with VBA:

Dim V1 As Variant
Dim V2 As Variant
V1 = Range("1:1").Value
V2 = Range("2:2").Value
Range("1:1").Value = V2
Range("2:2").Value = V1



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



wrote in message
oups.com...
Is there a quick way to switch the contents of two rows ?

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.misc
T Kirtley
 
Posts: n/a
Default how to switch rows

If you want to move the entire row you can use the following sequence:

Shift^Spacebar to select a row (or several consecutive rows), then
Ctrl^X to cut the row(s),
Move to the row where you want to insert the cut row and press
Shift^Spacebar again to mark where to insert the row, and finally,
Ctrl^+ (thats the plus key on the number keypad) which moves the row(s) you
cut to the new location.

Hope that helps,

TK

" wrote:

Is there a quick way to switch the contents of two rows ?

Thanks.


  #4   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default how to switch rows


Chip Pearson wrote:
You can do it with VBA:

Dim V1 As Variant
Dim V2 As Variant
V1 = Range("1:1").Value
V2 = Range("2:2").Value
Range("1:1").Value = V2
Range("2:2").Value = V1



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



Thanks that exchanges row 1 and row2. The next question would be how
can I get the macro to accept two parameters i and j and then exchange
row i and row j ?

Thanks.




wrote in message
oups.com...
Is there a quick way to switch the contents of two rows ?

Thanks.


  #5   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson
 
Posts: n/a
Default how to switch rows

Try something like

Dim V1 As Variant
Dim V2 As Variant
Dim I As Integer
Dim J As Integer
I = 5
J = 10
V1 = Range(I & ":" & I).Value
V2 = Range(J & ":" & J).Value
Range(I & ":" & I).Value = V2
Range(J & ":" & J).Value = V1



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


wrote in message
ups.com...

Chip Pearson wrote:
You can do it with VBA:

Dim V1 As Variant
Dim V2 As Variant
V1 = Range("1:1").Value
V2 = Range("2:2").Value
Range("1:1").Value = V2
Range("2:2").Value = V1



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



Thanks that exchanges row 1 and row2. The next question would
be how
can I get the macro to accept two parameters i and j and then
exchange
row i and row j ?

Thanks.




wrote in message
oups.com...
Is there a quick way to switch the contents of two rows ?

Thanks.






  #6   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default how to switch rows


T Kirtley wrote:
If you want to move the entire row you can use the following sequence:

Shift^Spacebar to select a row (or several consecutive rows), then
Ctrl^X to cut the row(s),
Move to the row where you want to insert the cut row and press
Shift^Spacebar again to mark where to insert the row, and finally,
Ctrl^+ (thats the plus key on the number keypad) which moves the row(s) you
cut to the new location.

Hope that helps,

TK


That works but its almost as much work as the dumb way (create an empty
row where you want the source row to go, copy paste the source row to
the empty target row and then delete the original source row).

But thanks any ways.

" wrote:

Is there a quick way to switch the contents of two rows ?

Thanks.



  #7   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default how to switch rows


Chip Pearson wrote:
Try something like

Dim V1 As Variant
Dim V2 As Variant
Dim I As Integer
Dim J As Integer
I = 5
J = 10
V1 = Range(I & ":" & I).Value
V2 = Range(J & ":" & J).Value
Range(I & ":" & I).Value = V2
Range(J & ":" & J).Value = V1



Now I get "out of stack space".

Also is there any way I can invoke the macro with I and J as input
parameters ?

Thanks again. (after all there is a dumb way to do it - I just wanted
to knoe if there was a fairly short way).

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


wrote in message
ups.com...

Chip Pearson wrote:
You can do it with VBA:

Dim V1 As Variant
Dim V2 As Variant
V1 = Range("1:1").Value
V2 = Range("2:2").Value
Range("1:1").Value = V2
Range("2:2").Value = V1



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



Thanks that exchanges row 1 and row2. The next question would
be how
can I get the macro to accept two parameters i and j and then
exchange
row i and row j ?

Thanks.




wrote in message
oups.com...
Is there a quick way to switch the contents of two rows ?

Thanks.



  #8   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson
 
Posts: n/a
Default how to switch rows

Try

Sub SwapRows(I As Integer, J As Integer)
Dim V1 As Variant
Dim V2 As Variant
On Error GoTo ErrH
Application.EnableEvents = False
V1 = Range(I & ":" & I).Value
V2 = Range(J & ":" & J).Value
Range(I & ":" & I).Value = V2
Range(J & ":" & J).Value = V1
ErrH:
Application.EnableEvents = True
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



wrote in message
oups.com...

Chip Pearson wrote:
Try something like

Dim V1 As Variant
Dim V2 As Variant
Dim I As Integer
Dim J As Integer
I = 5
J = 10
V1 = Range(I & ":" & I).Value
V2 = Range(J & ":" & J).Value
Range(I & ":" & I).Value = V2
Range(J & ":" & J).Value = V1



Now I get "out of stack space".

Also is there any way I can invoke the macro with I and J as
input
parameters ?

Thanks again. (after all there is a dumb way to do it - I just
wanted
to knoe if there was a fairly short way).

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


wrote in message
ups.com...

Chip Pearson wrote:
You can do it with VBA:

Dim V1 As Variant
Dim V2 As Variant
V1 = Range("1:1").Value
V2 = Range("2:2").Value
Range("1:1").Value = V2
Range("2:2").Value = V1



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



Thanks that exchanges row 1 and row2. The next question
would
be how
can I get the macro to accept two parameters i and j and
then
exchange
row i and row j ?

Thanks.




wrote in message
oups.com...
Is there a quick way to switch the contents of two rows ?

Thanks.





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
How to swap rows and columns? [email protected] Excel Discussion (Misc queries) 5 September 21st 05 08:07 AM
Hiding Rows if the linked rows are blank KG Excel Discussion (Misc queries) 9 May 18th 05 02:32 AM
How can I switch so that rows are referenced with letters, and co. willyv1 Excel Discussion (Misc queries) 1 March 17th 05 06:53 PM
Switch Rows and Columns Bonnie Excel Discussion (Misc queries) 3 March 3rd 05 03:38 PM
flexible paste rows function that inserts the right number of rows marika1981 Excel Discussion (Misc queries) 1 February 18th 05 02:40 AM


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