macro for cutting immediate cell below and pasting adjacent

sheetspread

Well-known Member
Joined
Sep 19, 2005
Messages
5,160
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

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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