Paste in reverse

BORUCH

Well-known Member
Joined
Mar 1, 2016
Messages
548
Office Version
  1. 365
Platform
  1. Windows
HI

can someone please provide me with a VBA that pastes backwards

for example
if i select cell A1 TO A5 and click copy and the try to paste it in Another column it would first paste A1 then A2 etc..
i'm looking for a VBA that would reverse the order it should first paste A5 then A4 then A3 etc..

Thanks
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I'm unsure what you mean exactly, but this small set of statements would take the contents of A1 and place then in B5. Therefore whilst the A range is selected in descent, the B range is filled in the reverse order:

Code:
b = 5
For a = 1 To 5
Range("B" & b).Value = Range("A" & a).Value
b = b - 1
Next
 
Upvote 0
I'm unsure what you mean exactly, but this small set of statements would take the contents of A1 and place then in B5. Therefore whilst the A range is selected in descent, the B range is filled in the reverse order:

Code:
b = 5
For a = 1 To 5
Range("B" & b).Value = Range("A" & a).Value
b = b - 1
Next

hi

two things

if possible to provide the whole code
and also its not always from column A to column B i would need a input box to select the destination to paste the data.
if you can add that extra code i would appreciate it
also its not always five cells its what i select before i hit the macro
thanks
 
Last edited:
Upvote 0
Bourch,

With the input box which allows you to select the destination, how do you want the paste to behave? Do you want it to start from that box you select and paste going up the column? Or do you want it to use that box as the top of the paste range?

For example, say you want to copy A1:A5. Do you want to select B5 to have it paste to B5, B4, B3, B2, B1? Or do you want to select B1 and have it paste to B5, B4, B3, B2, B1?
 
Upvote 0
Hia
Select the range to copy then run this
Code:
Sub RevPast()

    Dim Rws As Long
    Dim Dest As Range
    Dim SRng As Range
    Dim i As Long
    Dim r As Long
    
    r = 1
    Rws = Selection.Rows.Count
    Set SRng = Selection
    Set Dest = Application.InputBox("Select start point of paste range", Type:=8)
    For i = Rws To 1 Step -1
        Dest(r) = SRng(i)
        r = r + 1
    Next i
    
End Sub
 
Upvote 0
@BORUCH
You might want to add a check to the code to ensure the range selected is contiguous and in one column only.
 
Upvote 0
Hia
Select the range to copy then run this
Code:
Sub RevPast()

    Dim Rws As Long
    Dim Dest As Range
    Dim SRng As Range
    Dim i As Long
    Dim r As Long
    
    r = 1
    Rws = Selection.Rows.Count
    Set SRng = Selection
    Set Dest = Application.InputBox("Select start point of paste range", Type:=8)
    For i = Rws To 1 Step -1
        Dest(r) = SRng(i)
        r = r + 1
    Next i
    
End Sub

HI
OK his works PERFECT

if possible to add to this code, that if I select a range for ex. if I select a range from A1 to F10, and then I select in the input box let’s say A1, it should paste everything in reverse just like the standard copy paste in excel
is that possible?
 
Upvote 0
try
Code:
Sub RevPast()

    Dim Rws As Long
    Dim cols As Long
    Dim Dest As Range
    Dim SRng As Range
    Dim i As Long
    Dim r As Long
    
    r = 1
    Rws = Selection.Rows.Count
    cols = Selection.Columns.Count
    Set SRng = Selection
    Set Dest = Application.InputBox("Select start point of paste range", Type:=8)
    
    For i = Rws To 1 Step -1
        SRng.Rows(i).Copy Dest(r)
        r = r + 1
    Next i
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,198
Members
453,022
Latest member
RobertV1609

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