在Excel中按字长排序(按点或像素而不是字符数)

问题描述 投票:0回答:1

我需要按字长对 Excel 列进行排序

根据形式,所有值都具有相同的长度(字符数)。 但它们在屏幕上的长度并不相同(以点、像素或厘米为单位)。 第一种情况(字符数),len函数解决了问题 第二种模式如何实现?

excel sorting point
1个回答
0
投票

选择范围 (

A1:A4
) 并运行下一个宏:

Sub Macro1()
  Dim av As Variant, i As Integer, v As Variant, c As Range
  ReDim av(Selection.Cells.Count + 1)
  For i = 1 To Selection.Cells.Count
    av(i) = Selection.Cells(i)
  Next
  Selection.Cells.ClearContents
  For i = 1 To Selection.Cells.Count
    With Selection.Cells(i)
      .Value = av(i)
      .EntireColumn.AutoFit
      .Offset(0, 1) = .EntireColumn.Width
      .ClearContents
    End With
  Next
  For i = 1 To Selection.Cells.Count
    Selection.Cells(i) = av(i)
  Next
  Selection.EntireColumn.AutoFit
  Selection.CurrentRegion.Sort Selection.CurrentRegion.Columns(2), xlDescending
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.