How to create a macro to sort 2 non-adjacent columns?

helpneeded2

Board Regular
Joined
Jun 25, 2021
Messages
110
Office Version
  1. 365
Platform
  1. Windows
I have a sheet that contains ID numbers that a user enters in Column "A". They then hit a "retrieve data button" which populates data in Columns B to D. Then in Column "E" they enter the name of the user who entered the ID number.

Since from time to time, ID numbers will be added or removed in Column "A", I want a quick way to remove any blank cells. Sorting the ID's numerically is not necessarily required but is a nice added feature. However, I want the data in column E to always remain linked to Column A. Columns B to D are just XLookups grabbing data from a data sheet based on the ID number in Column A.

I would ideally like to make a "sort data" button to run a macro that sorts Columns A and E. I cannot figure out how to do this, since sorts need to be by an uninterrupted range. I would greatly prefer not to move my data in Column E to Column B to make this work, so I was wondering if this can be done in VBA?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
After some more searching, I think I found an example on Stackoverflow that partially addresses this but the results are pasted as a range on another sheet, as opposed back to the columns it obtained the data from, and I can't figure out how to do that.

 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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