It's really hard to tell what you intend but below is my best interpretation. Please try it.
Option Explicit
Sub Super_PasteInto1Col()
' 153
' Keyboard Shortcut: Ctrl+m
' TgtClm is the column where the results are deposited
Const TgtClm As Long = 18 ' change to suit
Dim SelRng As Range ' range selected by the user
Dim Clm As Long ' first column of SelRng
Dim C As Long ' loop counter: Columns
Dim Rt As Long ' target row
Set SelRng = Selection
Clm = SelRng.Column
Application.ScreenUpdating = False
With Columns(Clm)
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
For C = 0 To (SelRng.Columns.Count - 1)
' start the range in row 2 (leave headers untouched)
With Range(Cells(2, Clm + C), Cells(Rows.Count, Clm + C).End(xlUp))
' this range will start in row 1 if the column is otherwise blank
If .Row > 1 Then
.RemoveDuplicates Columns:=1, Header:=xlNo
.SortSpecial (xlPinYin)
If WorksheetFunction.CountA(Range(.Address)) Then
.Cut Cells(Rows.Count, TgtClm).End(xlUp).Offset(1)
End If
End If
Columns(Clm + C).ClearContents
End With
Next C
With Application
.CutCopyMode = False
.ScreenUpdating = False
End With
End Sub
In my test I had captions for the columns in row 1. I selected a number of these headers. The first one is of special significance because formulas in that column will be replaced by the values they generate. After that each column of the selection is sorted, after removing duplicates, and the remainder, if any, pasted to column 18 (change at the top of the code). The the column is cleared.
I couldn't figure out why you wanted to return to the original selection. However, the Selection
object is recorded at the very beginning and never changed. So it's available for whatever you have in mind with it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…