使用Excel VBA按列值对工作表数据进行排序 [英] Sorting Worksheet data by column values using Excel VBA
本文介绍了使用Excel VBA按列值对工作表数据进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在vba中开发了下一个用户表单,该表单从工作表中获取信息以显示信息
I have next userform developed in vba, which takes info from a worksheet for displaying info
我想按段按字母顺序对所有信息进行排序,这是代码:
I want to order all the info aphabetically by a Segment, this is the code:
Function llenarDatosTabla()
Dim vList As Variant
Dim ws As Worksheet: Set ws = Worksheets(BD_PRODXSIST)
ListBox1.Clear
With ws
If (IsEmpty(.Range("AA2").Value) = False) Then
Dim ultimoRenglon As Long: ultimoRenglon = devolverUltimoRenglonDeColumna("A1", BD_PRODXSIST)
vList = ws.Range("AA2:AA" & ultimoRenglon & ":AL2").Value
If IsArray(vList) Then
Me.ListBox1.List = vList
Else
Me.ListBox1.AddItem (vList)
End If
End If
Me.ListBox1.ListIndex = -1
End With
Set vList = Nothing
Set ws = Nothing
End Function
如何使其按"AD"(SEGMENTO)列排序?
how to make it ordered by 'AD' (SEGMENTO) column???
推荐答案
您可以使用VBA语句按如下升序对Excel工作表进行排序:
You can sort your Excel Worksheet in ascending order using VBA statement like the following:
Columns("A:XFD").Sort key1:=Range("AD:AD"), order1:=xlAscending, Header:=xlYes
注意:在列范围Columns("A:XFD")
而不是XFD
中,输入与您的案例有关的最后使用的列,例如Columns("A:DD")
.
Note: in the column range Columns("A:XFD")
instead of XFD
enter the last used column pertinent to your case, e.g. Columns("A:DD")
.
希望这会有所帮助.
这篇关于使用Excel VBA按列值对工作表数据进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文