VBA: Copy data from every other row, paste it in previous row, delete copied row

JohnJames

New Member
Joined
Jan 27, 2014
Messages
5
Hi all!

A team I work with sends us reports that we want to put in a database, unfortunately the data for one entry is on multiple lines and it had data that was uneeded. I figured out how to delete the unneeded data and get rid of the blank spaces, just having trouble with the last part which is copying the data in every other row, pasting it in the previous row then deleting the copied row. Fig.1 is what I have currently, I want my data to look like Fig.2.

I found the following code, but don't know how I could make this work for x amount of rows or my range:

Code:
Set Rng = Range("B7")
Range(Rng.Address).Offset(-1, 0).Value = Rng.Value

Please look at my

Fig.1
[TABLE="width: 500"]
<tbody>[TR]
[TD]dataR1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]data11[/TD]
[TD]data12[/TD]
[TD]data13[/TD]
[TD]data14[/TD]
[TD]data15[/TD]
[/TR]
[TR]
[TD]dataR2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]data21[/TD]
[TD]data22[/TD]
[TD]data23[/TD]
[TD]data24[/TD]
[TD]data25[/TD]
[/TR]
[TR]
[TD]dataR3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]data31[/TD]
[TD]data32[/TD]
[TD]data33[/TD]
[TD]data34[/TD]
[TD]data35[/TD]
[/TR]
</tbody>[/TABLE]

Fig.2
[TABLE="width: 500"]
<tbody>[TR]
[TD]dataR1[/TD]
[TD]data11[/TD]
[TD]data12[/TD]
[TD]data13[/TD]
[TD]data14[/TD]
[TD]data15[/TD]
[/TR]
[TR]
[TD]dataR2[/TD]
[TD]data21[/TD]
[TD]data22[/TD]
[TD]data23[/TD]
[TD]data24[/TD]
[TD]data25[/TD]
[/TR]
[TR]
[TD]dataR3[/TD]
[TD]data31[/TD]
[TD]data32[/TD]
[TD]data33[/TD]
[TD]data34[/TD]
[TD]data35[/TD]
[/TR]
</tbody>[/TABLE]

Any help would be greatly appreciated!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try:
Code:
Dim LR  As Long
Dim LC  As Long

LR = Application.Max(Cells(Rows.count, 2).End(xlUp).row, 7) - 6
LC = Cells(7, Columns.count).End(xlToLeft).column - 1

Cells(6, 2).Resize(LR, LC).SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
 
Last edited:
Upvote 0

Forum statistics

Threads
1,225,476
Messages
6,185,209
Members
453,283
Latest member
Shortm88

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