Switching data in two different rows

TheShaunMichael

Board Regular
Joined
Oct 24, 2009
Messages
57
Is there a way to swith the data in two rows without using the insert & delete properties? Possibly creating an array?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Is there a way to swith the data in two rows without using the insert & delete properties? Possibly creating an array?
Like this?

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> SwapRows()<br>    <SPAN style="color:#00007F">Dim</SPAN> r1Data<br>    <SPAN style="color:#00007F">Dim</SPAN> r1 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, r2 <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    r1 = 4: r2 = 7 <SPAN style="color:#007F00">'<-- Rows to swap</SPAN><br>    r1Data = Rows(r1).Value<br>    Rows(r1).Value = Rows(r2).Value<br>    Rows(r2).Value = r1Data<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Last edited:
Upvote 0
Oh how obvious the answer seems in retrospection.

Let me however add one more layer of complexity. Here's the challenge: I have information in rows 12-15 of my spreadsheet. A userform opens and a listbox is populated with the values of B12:B15. Two command buttons allows the user to move items in the listbox up or down. When the user clicks okay, I then want the corresponding rows to change orders. Does that make sense?

So, i'm thinking of testing for the value in B12:B16 and assigning it to a variable, at which point I should be able to use the code you wrote. Thoughts???
 
Upvote 0
Sorry, Userforms and their components are not one of my strong points. Hopefully somebody with more expertise in that area will step in.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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