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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,043
Office Version
  1. 365
Platform
  1. Windows
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
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,866
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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]
 

meuby

New Member
Joined
Mar 14, 2019
Messages
3
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!!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,043
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

You're welcome & thanks for the feedback
 

meuby

New Member
Joined
Mar 14, 2019
Messages
3
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,600
Messages
5,832,651
Members
430,151
Latest member
Kacbear

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
Top