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

Hi all

I am trying to build a macro that switches two rows in a worksheet.
i.e A A A A A
D D D D D
switches to
D D D D D
A A A A A
I can do it with absolute cell references but can it be done when the user
selects any two rows in a worksheet, as my way only work in the named cells?

Cheers

TM


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Switching Selections

This needs more error trapping (i.e. that the multiple areas have the same number of rows and
columns etc), and switching off events, screen updatingm=, recalculation, etc, but it may give
you some ideas:

Sub SwitchRows()
Dim Rng1 As Range
Dim Rng2 As Range
Dim v1 As Variant
Dim v2 As Variant

With Selection
If .Areas.Count = 1 Then
If .Rows.Count 1 Then
Set Rng1 = .Rows(1)
Set Rng2 = .Rows(2)
Else
MsgBox "Only one row selected", vbOKOnly
Exit Sub
End If
Else
Set Rng1 = .Areas(1).Rows(1)
Set Rng2 = .Areas(2).Rows(1)
End If
End With

v1 = Rng1.Value
v2 = Rng2.Value
Rng1.Value = v2
Rng2.Value = v1

End Sub


On Sat, 08 Nov 2003 01:19:47 GMT, "TM" wrote:

Hi all

I am trying to build a macro that switches two rows in a worksheet.
i.e A A A A A
D D D D D
switches to
D D D D D
A A A A A
I can do it with absolute cell references but can it be done when the user
selects any two rows in a worksheet, as my way only work in the named cells?

Cheers

TM


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Switching Selections

Thankyou Myrna

It works great

TM

"Myrna Larson" wrote in message
...
This needs more error trapping (i.e. that the multiple areas have the same

number of rows and
columns etc), and switching off events, screen updatingm=, recalculation,

etc, but it may give
you some ideas:

Sub SwitchRows()
Dim Rng1 As Range
Dim Rng2 As Range
Dim v1 As Variant
Dim v2 As Variant

With Selection
If .Areas.Count = 1 Then
If .Rows.Count 1 Then
Set Rng1 = .Rows(1)
Set Rng2 = .Rows(2)
Else
MsgBox "Only one row selected", vbOKOnly
Exit Sub
End If
Else
Set Rng1 = .Areas(1).Rows(1)
Set Rng2 = .Areas(2).Rows(1)
End If
End With

v1 = Rng1.Value
v2 = Rng2.Value
Rng1.Value = v2
Rng2.Value = v1

End Sub


On Sat, 08 Nov 2003 01:19:47 GMT, "TM" wrote:

Hi all

I am trying to build a macro that switches two rows in a worksheet.
i.e A A A A A
D D D D D
switches to
D D D D D
A A A A A
I can do it with absolute cell references but can it be done when the

user
selects any two rows in a worksheet, as my way only work in the named

cells?

Cheers

TM




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
Switching between workbooks Jim Excel Discussion (Misc queries) 5 July 28th 07 03:19 AM
Switching Information zephyr Excel Discussion (Misc queries) 2 February 21st 06 07:25 AM
Not switching to next worksheet G Setting up and Configuration of Excel 2 November 23rd 05 03:33 PM
Switching cells DrJBN Excel Discussion (Misc queries) 5 May 6th 05 10:45 PM
Switching between worksheets Curious[_3_] Excel Programming 2 November 7th 03 04:56 PM


All times are GMT +1. The time now is 10:21 PM.

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"