moving a row of cells within a range (drag n drop type thing)

RobbieC

Active Member
Joined
Dec 14, 2016
Messages
376
Office Version
  1. 2010
Platform
  1. Windows
Hi there, I have been puzzling over this for a while, but I cannot come up with any form of solution.

I have a series of rows in a range - they are all grouped in a series of 2 rows containing data

moveRows.jpg


I have a maximum of 40 rows, so I can have 20 'double line' entries on my sheet - the rest of the sheet is full of data, so I am only looking at Range E10:K49

Each of these 'double rows' I have assigned a name range dataRow1, dataRow2, dataRow3... dataRow20

I can get 2 rows to swap positions by using:

Code:
Dim Range1 As Variant, Range2 As Variant
      Range1 = Worksheets("DataSheet").Range("dataRow" & Row)
      Range2 = Worksheets("DataSheet").Range("dataRow" & OtherRow)
      Worksheets("DataSheet").Range("dataRow" & Row) = Range2
      Worksheets("DataSheet").Range("dataRow" & OtherRow) = Range1

but what I'm really looking to do is find a simple way for a user to potentially reposition any row anywhere within the range. I was thinking perhaps employing a userform to display all the rows and somehow re-arrange them there as a visual aid and then the sheet would update accordingly...

I know this is a big ask, but I have searched everywhere for something which will allow me to do this...

If you can perhaps point me in the right direction, I'd be very grateful

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try this:-
This code works in range "E10:K49"
Paste code into worksheet module, Make sure its at the Top of the module!!!!
When you have the code loaded in the active sheet.
Double click any cell in any of the range Pairs (DataRow1 to DataRow20), then double click in any of the other pairs.
The two ranges should then be swapped.

Code:
Option Explicit
[COLOR="Navy"]Dim[/COLOR] rng [COLOR="Navy"]As[/COLOR] Range
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_BeforeDoubleClick(ByVal Target [COLOR="Navy"]As[/COLOR] Range, Cancel [COLOR="Navy"]As[/COLOR] Boolean)
[COLOR="Navy"]Dim[/COLOR] temp [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Dim[/COLOR] My [COLOR="Navy"]As[/COLOR] Variant, M [COLOR="Navy"]As[/COLOR] Range, Ray [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Set[/COLOR] My = Range("DataRow1,DataRow2,DataRow3,DataRow4,DataRow5,DataRow6,DataRow7,DataRow8,DataRow9,DataRow10,DataRow11,DataRow12,DataRow13,DataRow14,DataRow15,DataRow16,DataRow17,DataRow18,DataRow19,DataRow20")
    [COLOR="Navy"]If[/COLOR] rng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] M [COLOR="Navy"]In[/COLOR] My.Areas
          [COLOR="Navy"]If[/COLOR] Not Intersect(Target, M) [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]Set[/COLOR] rng = M
            [COLOR="Navy"]Exit[/COLOR] For
          [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Next[/COLOR] M
[COLOR="Navy"]ElseIf[/COLOR] Not rng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
 [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] M [COLOR="Navy"]In[/COLOR] My.Areas
    [COLOR="Navy"]If[/COLOR] Not Intersect(Target, M) [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
      temp = M
      M(1).Resize(UBound(temp, 1), UBound(temp, 2)).Value = rng.Value
      rng.Value = temp
      [COLOR="Navy"]Set[/COLOR] rng = Nothing
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] M
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top