Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Moving cells

All data is kept in a single column, the number of rows varies (up to 2ooo)

How to move the cells in col. A:A next to the higher cell in Col. B:B?

Example:

A2 goes to B1 (row 2 thereby is empty now)
A4 goes to B3 (row 4 thereby is empty now)
A6 goes to B5 (row 6 thereby is empty now)
etc.

I´m sure there is a better way than record a macro that does it one by one.
(And where to stop?)



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default Moving cells

Here's a macro that cuts everything from the currently select cell down to
the first blank and move it one cell right and one cell up:
Sub MoveRightUp()
Range(ActiveCell,Activecell.End(xlDown)).Cut ActiveCell.Offset(-1,1)
End Sub
--
Charles Chickering

"A good example is twice the value of good advice."


"Tatebana" wrote:

All data is kept in a single column, the number of rows varies (up to 2ooo)

How to move the cells in col. A:A next to the higher cell in Col. B:B?

Example:

A2 goes to B1 (row 2 thereby is empty now)
A4 goes to B3 (row 4 thereby is empty now)
A6 goes to B5 (row 6 thereby is empty now)
etc.

I´m sure there is a better way than record a macro that does it one by one.
(And where to stop?)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Moving cells

Sub tatebana()
n = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To n Step 2
Cells(i - 1, 2).Value = Cells(i, 1).Value
Cells(i, 1).Clear
Next
End Sub

--
Gary''s Student
gsnu200712


"Tatebana" wrote:

All data is kept in a single column, the number of rows varies (up to 2ooo)

How to move the cells in col. A:A next to the higher cell in Col. B:B?

Example:

A2 goes to B1 (row 2 thereby is empty now)
A4 goes to B3 (row 4 thereby is empty now)
A6 goes to B5 (row 6 thereby is empty now)
etc.

I´m sure there is a better way than record a macro that does it one by one.
(And where to stop?)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Moving cells

Thank you Charles,

I wrote the following:

On running it I got a Run-Time Error 1004: "Application defined or Object
defined Error"

Where did I mess up?



"Charles Chickering" wrote:

Here's a macro that cuts everything from the currently select cell down to
the first blank and move it one cell right and one cell up:
Sub MoveRightUp()
Range(ActiveCell,Activecell.End(xlDown)).Cut ActiveCell.Offset(-1,1)
End Sub
--
Charles Chickering

"A good example is twice the value of good advice."


"Tatebana" wrote:

All data is kept in a single column, the number of rows varies (up to 2ooo)

How to move the cells in col. A:A next to the higher cell in Col. B:B?

Example:

A2 goes to B1 (row 2 thereby is empty now)
A4 goes to B3 (row 4 thereby is empty now)
A6 goes to B5 (row 6 thereby is empty now)
etc.

I´m sure there is a better way than record a macro that does it one by one.
(And where to stop?)



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Moving cells

I wrote the following little piece

n = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To n Step 2
Cells(i - 1, 2).Value = Cells(i, 1).Value
Cells(i, 1).Clear
Next
Columns("B:C").Select
Columns("B:C").EntireColumn.AutoFit
Range("D1").Select

End Sub

When runing it, it jumps imediately to the "Next" line


"Gary''s Student" wrote:

Sub tatebana()
n = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To n Step 2
Cells(i - 1, 2).Value = Cells(i, 1).Value
Cells(i, 1).Clear
Next
End Sub

--
Gary''s Student
gsnu200712


"Tatebana" wrote:

All data is kept in a single column, the number of rows varies (up to 2ooo)

How to move the cells in col. A:A next to the higher cell in Col. B:B?

Example:

A2 goes to B1 (row 2 thereby is empty now)
A4 goes to B3 (row 4 thereby is empty now)
A6 goes to B5 (row 6 thereby is empty now)
etc.

I´m sure there is a better way than record a macro that does it one by one.
(And where to stop?)





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Moving cells

Make sure column A is not empty
--
Gary''s Student
gsnu200712


"Tatebana" wrote:

I wrote the following little piece

n = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To n Step 2
Cells(i - 1, 2).Value = Cells(i, 1).Value
Cells(i, 1).Clear
Next
Columns("B:C").Select
Columns("B:C").EntireColumn.AutoFit
Range("D1").Select

End Sub

When runing it, it jumps imediately to the "Next" line


"Gary''s Student" wrote:

Sub tatebana()
n = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To n Step 2
Cells(i - 1, 2).Value = Cells(i, 1).Value
Cells(i, 1).Clear
Next
End Sub

--
Gary''s Student
gsnu200712


"Tatebana" wrote:

All data is kept in a single column, the number of rows varies (up to 2ooo)

How to move the cells in col. A:A next to the higher cell in Col. B:B?

Example:

A2 goes to B1 (row 2 thereby is empty now)
A4 goes to B3 (row 4 thereby is empty now)
A6 goes to B5 (row 6 thereby is empty now)
etc.

I´m sure there is a better way than record a macro that does it one by one.
(And where to stop?)



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving text around cells without moving boarder lines Dale Excel Discussion (Misc queries) 1 December 15th 09 06:14 PM
Enter Key + Dragging Cells / Moving Cells Tim Excel Discussion (Misc queries) 2 September 24th 08 11:14 AM
Arrow Keys Moving Window Frame instead of Moving Between Cells nemmex Excel Discussion (Misc queries) 2 April 9th 07 09:08 AM
moving cells Paul New Users to Excel 5 January 23rd 06 12:57 PM
Cells(col,row) keep moving to lower case and I can not ref. a cells in a differnet sheet WayneL[_2_] Excel Programming 2 April 25th 05 11:27 PM


All times are GMT +1. The time now is 04:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"