Move Part of a Row Up and Over

meuby

New Member
Joined
Mar 14, 2019
Messages
3
Wondering if there's a way with VBA to do the following.


I need to get the data in C:2 and D:2 into E:1 and F:1, the data from C:3 and D:3 into G:1 and H:1. I need to repeat for the entire sheet. Can this be done with VBA?

open

https://drive.google.com/open?id=189R34HQhkflk6wh-mlxhj6aJtblTX5Ed
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi & welcome to MrExcel
How about
Code:
Sub meuby()
   Dim rng As Range
   
   For Each rng In Range("B:B").SpecialCells(xlBlanks).Areas
      rng.Offset(, 1).Resize(1, 2).Copy rng.Offset(-1, 3).Resize(1, 2)
      rng.Offset(1, 1).Resize(1, 2).Copy rng.Offset(-1, 5).Resize(1, 2)
   Next rng
End Sub
 
Upvote 0
Wondering if there's a way with VBA to do the following.


I need to get the data in C:2 and D:2 into E:1 and F:1, the data from C:3 and D:3 into G:1 and H:1. I need to repeat for the entire sheet. Can this be done with VBA?

See if this macro does what you want...
Code:
[table="width: 500"]
[tr]
	[td]Sub UpAndOver()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "C").End(xlUp).Row
  Range("E1").Resize(, 2 * LastRow - 2) = Split(Join(Application.Transpose(Evaluate(Replace("C2:C#&char(9)&D2:D#", "#", LastRow))), Chr(9)), Chr(9))
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Hi & welcome to MrExcel
How about
Code:
Sub meuby()
   Dim rng As Range
   
   For Each rng In Range("B:B").SpecialCells(xlBlanks).Areas
      rng.Offset(, 1).Resize(1, 2).Copy rng.Offset(-1, 3).Resize(1, 2)
      rng.Offset(1, 1).Resize(1, 2).Copy rng.Offset(-1, 5).Resize(1, 2)
   Next rng
End Sub

This worked - THANK YOU!!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Just wondering... did the code I posted work as well or did it not work for you?

Hi - I apologize for the delay.

Actually, the macro you provided moved everything up and across, but it moved it all to row 1.

Thank you...hope this feedback helps you.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,375
Members
448,955
Latest member
BatCoder

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