VBA在一列上按A-Z排序 [英] VBA Sort A-Z on One Column

查看:68
本文介绍了VBA在一列上按A-Z排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据列M上的A-Z升序对所有具有A-Z的行进行排序我已经尝试了以下方法,但是对我可能做错的事情没有任何作用?

How do I sort all my rows which I have A-Z based on ascending A-Z on column M I have tried the following but it hasn't worked any idea what I might be doing wrong?

Range("A1", Range("Z" & Rows.Count).End(xlUp)).Sort [M1], xlAscending

推荐答案

记录一个宏,在其中选择要排序的列.例如,我记录了一个宏,该宏以升序对M列进行排序:

Record a macro where you select the column you want to be sorted. As an example, I've recorded a macro that sorts column M in ascending order:

Sub SortAsc2()

Dim LastRow As Long

LastRow = Cells(Rows.Count, "M").End(xlUp).Row

Columns("M:M").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("M1"), _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
    .SetRange Range("M1:M" & LastRow)
    .Header = xlGuess
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With

End Sub

这篇关于VBA在一列上按A-Z排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆