macro for cutting immediate cell below and pasting adjacent

sheetspread

Well-known Member
Joined
Sep 19, 2005
Messages
5,120
Say I have:

Red
Orange
Yellow
Green
Blue
Indigo
Violent

in a column (no other text)

and want to cut the cell immediately below, then paste it next to the one above it:

Red Orange
Yellow Green
Blue Indigo


.......yadda yadda

What code should I use?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

try this
Code:
Option Explicit

Sub test()
Dim rng As Range
Dim arr As Variant
Dim LR As Long
Dim i As Long

LR = Cells(Rows.Count, 1).End(xlUp).Row

Set rng = Range("A1:A" & LR)
arr = rng

    For i = 2 To LR Step 2
    arr(i / 2, 1) = arr(i - 1, 1) & " " & arr(i, 1)
    Next i
    If LR Mod 2 = 1 Then arr(i / 2, 1) = arr(i - 1, 1)

rng = arr
Range("A" & Int(LR / 2) + 1 + LR Mod 2 & ":A" & LR).ClearContents

Erase arr
End Sub
for more info about this technique see http://puremis.net/excel/code/053.shtml

kind regards,
Erik
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Re: Whoa that's wild

Thanks Erik, you know your code
You're WELCOME :)

in fact it's knowing some code, taken from helpfiles or internet
+
some trial and error (based on mathematical logic)

you too can find this kinda stuff now
 

Forum statistics

Threads
1,137,202
Messages
5,680,145
Members
419,886
Latest member
Pulpboi

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