Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default select row(s) and shift up one place automatically

I want to swap the selected row with the one who is above. So I can
rearrange my products in the right way.

In this example I swap row 3 with 2.

Sub swaprows()
Rows("3:3").Select
Selection.Cut
Rows("2:2").Select
Selection.Insert Shift:=xlDown
End sub

But it is also possible that row 76 is swapped with row 75 depending
on which row is selected by the user.

And it is also possible that row 20 to 25 is selected and that it must
be 19 to 24.

Does anybody have an idea?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default select row(s) and shift up one place automatically

On 30 okt, 11:43, bartman1980 wrote:
I want to swap the selected row with the one who is above. So I can
rearrange my products in the right way.

In this example I swap row 3 with 2.

Sub swaprows()
Rows("3:3").Select
Selection.Cut
Rows("2:2").Select
Selection.Insert Shift:=xlDown
End sub

But it is also possible that row 76 is swapped with row 75 depending
on which row is selected by the user.

And it is also possible that row 20 to 25 is selected and that it must
be 19 to 24.

Does anybody have an idea?


I think I already got it:

To shift up
Selection.Cut
Rows(ActiveCell.Row - 1 & ":" & ActiveCell.Row - 1).Select
Selection.Insert Shift:=xlDown

To shift down
Selection.Cut
Rows(ActiveCell.Row + 2 & ":" & ActiveCell.Row + 2).Select
Selection.Insert Shift:=xlDown
Rows(ActiveCell.Row - 1 & ":" & ActiveCell.Row - 1).Select

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default select row(s) and shift up one place automatically

On Oct 30, 11:52 pm, bartman1980 wrote:
On 30 okt, 11:43, bartman1980 wrote:



I want to swap the selected row with the one who is above. So I can
rearrange my products in the right way.


In this example I swap row 3 with 2.


Sub swaprows()
Rows("3:3").Select
Selection.Cut
Rows("2:2").Select
Selection.Insert Shift:=xlDown
End sub


But it is also possible that row 76 is swapped with row 75 depending
on which row is selected by the user.


And it is also possible that row 20 to 25 is selected and that it must
be 19 to 24.


Does anybody have an idea?


I think I already got it:

To shift up
Selection.Cut
Rows(ActiveCell.Row - 1 & ":" & ActiveCell.Row - 1).Select
Selection.Insert Shift:=xlDown

To shift down
Selection.Cut
Rows(ActiveCell.Row + 2 & ":" & ActiveCell.Row + 2).Select
Selection.Insert Shift:=xlDown
Rows(ActiveCell.Row - 1 & ":" & ActiveCell.Row - 1).Select


I couldn't get your shift down to work.

My attempts are...

Public Sub SwapRowsUp()
Selection.EntireRow.Select
Selection.Cut
Range(Cells(ActiveCell.Row - 1, 1), _
Cells(ActiveCell.Row + Selection.Rows.Count - 1, 1)).EntireRow.Insert
_
xlDown
End Sub

Public Sub SwapRowsDown()
Selection.EntireRow.Select
Selection.Cut
Range(Cells(ActiveCell.Row + 2 * Selection.Rows.Count, 1), _
Cells(ActiveCell.Row + 3 * Selection.Rows.Count - 1,
1)).EntireRow.Insert _
xlDown
End Sub

Ken Johnson

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
After press Shift+Ctrl+Up arrw key it does not select up side Col sudhir Excel Discussion (Misc queries) 0 May 30th 09 08:14 AM
hold shift key down to select multiple cells dean Excel Discussion (Misc queries) 1 September 19th 08 06:10 PM
Select which cell enter will place the cursor mbing916 Excel Discussion (Misc queries) 3 May 1st 07 05:17 PM
Control + Shift + Up/Down not allowing me to select multiple cells. [email protected] Excel Discussion (Misc queries) 1 April 5th 07 02:31 PM
Automatically place hyphen Mex New Users to Excel 3 February 28th 07 02:47 PM


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