Help

Shalbriri

Board Regular
Joined
Nov 4, 2010
Messages
93
Code:
Sheets("Sheet2").Select
Range("d2:E33").Offset(0, 0).Select
Selection.Copy
Range("D2:E33").Offset(0, 1).PasteSpecial
Range("C2:D33").Offset(0, 0).Select
Selection.Copy
Range("C2:D33").Offset(0, 1).PasteSpecial
This is my code, its perfectly fine, tho, if someone could help me out and give me pointers on how to make this code into a loop.
since i need to move 2 columns of data to the right, by one step.




The idea is to move data from C to D to E to F and so on.
but the procedure must be backwards, if you get my point.
http://imageshack.us
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,890
Office Version
  1. 365
Platform
  1. Windows
Try:
Code:
Sub MoveMyColumns ()
Dim i as Long, j as Long
j = Cells(1, Columns.Count).End(xlToLeft).Column - 2
For i = j to 3 Step -1
Range(cells(2,j), cells(33, j + 1)).copy
cells(2,j+1).PasteSpecial
Next i
End Sub
 
Last edited:

Dryver14

Well-known Member
Joined
Mar 22, 2010
Messages
2,396
if you work backwards and copy f to d then d to c will you not just put column f in every column?
 

Shalbriri

Board Regular
Joined
Nov 4, 2010
Messages
93
Why is this

Range(cells(2,j), cells(33, j + 1).copy
in red ??

EDIT
) was missing :D
 

AMAS

Active Member
Joined
Apr 11, 2010
Messages
472

ADVERTISEMENT

Also just a quick note... you almost never need to use select. So your original code can also be:

Code:
Range("d2:E33").Offset(0, 0).Copy
Range("D2:E33").Offset(0, 1).PasteSpecial
Range("C2:D33").Offset(0, 0).Copy
Range("C2:D33").Offset(0, 1).PasteSpecial

Just something I picked up along the way.

Hope it helps.

AMAS
 

Shalbriri

Board Regular
Joined
Nov 4, 2010
Messages
93
Shalbriri said:
The idea is to move data from C to D to E to F and so on.
but the procedure must be backwards, if you get my point.

sry i miss led you, the first part is the one i am looking for.
C to D
D to E
E to F
F to infinity
 

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,890
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

If you move C to D and then D to E, why not just move C to E??
 

Dryver14

Well-known Member
Joined
Mar 22, 2010
Messages
2,396
that just moves it the other way so every column would be c

you need to select the whole range and move it accross one at the same time
 

Shalbriri

Board Regular
Joined
Nov 4, 2010
Messages
93
Im so sorry guys this concept overall doesn't help me at all, since the idea was that the values under D are the starting value of products in storage, and C would've been the status value of the moment, and when ever new items were to be inserted into the storage the at the moment values would've become the starting values.

And the reason why it doesn't help me is that new items come randomly in a month. So it would've moved all the data and would've left empty gaps in the worksheet ...
 

Forum statistics

Threads
1,141,728
Messages
5,708,130
Members
421,548
Latest member
douae

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