vba sort

charly1

Board Regular
Joined
Jul 18, 2023
Messages
87
Office Version
  1. 365
Platform
  1. Windows
Hi all, and thanks in advance for any help that may be offered.
The code attached allows me to select a column of data and then to copy that data into some other place in an excel spreadsheet. It will also take every alternate cell and copy it into the adjoining column parallel to the cell immediately above. Ime not sure if I had to explain all that for my q, but anyway, this is what i am trying to do.
The column of data that I select I need that it first be sorted into the reverse order, i.e the last cell of the selected data to become the first and so on. From then on, my macro should continue to run as it currently does.
Thank You so much for any help in advance.
VBA Code:
Sub MoveRange()
Dim rng As Range
Dim InputRng As Range, OutRng As Range
On Error GoTo ErrorMessage
Dim xTitleId As String
Dim i As Long
xTitleId = "Hello"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
Set OutRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
Set InputRng = InputRng.Columns(1)
For i = 1 To InputRng.Rows.Count Step 2
    OutRng.Resize(1, 2).Value = Array(InputRng.Cells(i, 1).Value, InputRng.Cells(i + 1, 1).Value)
    Set OutRng = OutRng.Offset(1, 0)
Next
ErrorMessage:
Exit Sub
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hello!
VBA Code:
Dim rvrs(), i&, c As Range
rvrs = Selection
    For Each c In Selection
        c.Value = rvrs(UBound(rvrs) - i, 1)
        i = i + 1
    Next c
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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