請幫助我,我想對名字列進行排序,使每個名字在每個空白單元格之后開始。
我希望它看起來像這樣。請幫助,這是一個相當長的列
我希望它看起來像這樣。
uj5u.com熱心網友回復:
在制作陣列之前,我可能最好先移除空的范圍,但這里有一個分配名字的方法:
加載范圍,然后將其添加到陣列。
將范圍加載到一個陣列,然后通過數字并尋找空的范圍。 這假定我們正在處理列 "A "和 "B"(1和2),從頂部開始。
Sub test()
Dim arr As Variant
Dim LastRow As Long, i As Long, j As Long.
lastRow = Cells(Rows.Count, "A").End(xlUp) 。
arr = Application.Transpose(Range("B2:B" & lastRow))
Range("B2:B" & lastRow).Clear
j = 1
For i = 2 To lastRow
Cells(i, 2) = arr(j)
j = j 1 1 = arr(j)
如果 j >= UBound(arr) Then Exit For
While arr(j) = "" And j < UBound(arr)
j = j 1; UBound(arr)
終止
While Not Cells(i, 1).Value = ""
i = i 1.
補上
Next i
End Sub
任何遺留的名字都將被洗掉
。uj5u.com熱心網友回復:
Option Explicit>
Sub SetNamePosition()
Dim arr As Variant
Dim i As Long: i = 1 ' for Loop
Dim j As Long: j = 1 ' for Array
Dim lastRow As Long: lastRow = Cells(Rows.Count, 1).End(xlUp) . Row
Dim rngColB As Range: Set rngColB = Range("B2:B"/span> & lastRow)
Dim rngNames As Range: Set rngNames = Range("C1") ' 臨時范圍。
' 只獲得B列的名字
rngColB.SpecialCells(xlCellTypeConstants, 2).Copy
rngNames.PasteSpecial(xlPasteValues)
Application.CutCopyMode = False.
Set rngNames = Range(rngNames, rngNames.End(xlDown)
' 加載rngNames到陣列。
arr = Application.Transpose(rngNames)
' 清除B列和rngNames的rng。
rngColB.Clear
rngNames.Clear
' 插入名字。
For i = 2 To lastRow
' 設定名稱。
Cells(i, 1).Offset(0, 1) .Value = arr(j)
' 查找下一個單元格。
i = Cells(i, 1).End(xlDown).Row 1.
j=j 1。
Next i
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/310863.html
標籤:


