在excel工作簿中对有多个工作表,由于个人需要,对每个工作表中某一值的比较大小后,然后进行排序。
由于vba中字典对应值比较难以排序,所以就分为两步
第一步是提取工作表名和对应字段写到工作表中:
- Sub getname()
- Dim sheet As Worksheet
- Dim k As Integer
- k = 17
- For Each sheet In Worksheets
- Cells(k, 1) = sheet.Name
- Cells(k, 2) = sheet.Cells(2, 3)
- k = k + 1
- Next
- End Sub
得到后排序:
再利用第二个函数对排序后的工作表名进行相应的移动:
- Sub sortmysheet()
- Dim sheet As Worksheet
- Dim sheetname As String
- Dim i As Integer
- Set sheet = ActiveSheet
- For i = 1 To 41
- sheetname = sheet.Cells(i, 1)
- Sheets(sheetname).Move after:=Sheets(i)
- Next
- sheet.Activate
- End Sub
其中 sheet是新建了一个空白工作表,然后一个41行
联系客服