请使用VBA编写,按照行政区及成交单价从高到低排序
时间: 2023-12-14 18:36:48 浏览: 76
以下是按照行政区及成交单价从高到低排序的VBA代码:
```
Sub SortByRegionAndPrice()
Dim lastRow As Long
Dim sortRange As Range
' Determine last row in the sheet
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
' Set the range to be sorted (assuming data starts in column A and ends in column C)
Set sortRange = Range("A2:C" & lastRow)
' Sort the range by region (column A) in ascending order and then by price (column C) in descending order
sortRange.Sort key1:=Range("A2"), order1:=xlAscending, key2:=Range("C2"), order2:=xlDescending, Header:=xlYes
End Sub
```
请注意,这段代码假定您的数据从第二行开始,并且第一行是标题行。如果您的工作表结构与此不同,请相应地更改代码中的范围。此外,您可以根据需要更改排序顺序和排序列。
阅读全文