1. Trang chủ
  2. » Giáo án - Bài giảng

Sort worksheets trong excel

3 179 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Sort worksheets trong Excel
Thể loại Guide
Định dạng
Số trang 3
Dung lượng 34,5 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

SORTSHEET TRONG EXCEL Code: instructions for use Option Explicit Sub SortWorksheets Dim N As Integer Dim M As Integer Dim FirstWSToSort As Integer Dim LastWSToSort As Integer Dim

Trang 1

SORTSHEET TRONG EXCEL

Code: instructions for use

Option Explicit

Sub SortWorksheets()

Dim N As Integer

Dim M As Integer

Dim FirstWSToSort As Integer

Dim LastWSToSort As Integer

Dim SortDescending As Boolean

SortDescending = False

If ActiveWindow.SelectedSheets.Count = 1 Then

'Change the 1 to the worksheet you want sorted first

FirstWSToSort = 1

LastWSToSort = Worksheets.Count

Else

With ActiveWindow.SelectedSheets

For N = 2 To Count

If Item(N - 1).Index <> Item(N).Index -

1 Then

MsgBox "You cannot sort non-adjacent sheets"

Exit Sub

End If

Next N

FirstWSToSort = Item(1).Index

LastWSToSort = Item(.Count).Index

End With

End If

Trang 2

For M = FirstWSToSort To LastWSToSort

For N = M To LastWSToSort

If SortDescending = True Then

If UCase(Worksheets(N).Name) >

UCase(Worksheets(M).Name) Then

Worksheets(N).Move

Before:=Worksheets(M)

End If

Else

If UCase(Worksheets(N).Name) <

UCase(Worksheets(M).Name) Then

Worksheets(N).Move

Before:=Worksheets(M)

End If

End If

Next N

Next M

End Sub

How to

use:

1 Copy the code above

2 Open the Excel file in which you want to use the code

3 Hit Alt+F11 to open the Visual Basic Editor (VBE) window

4 From the menu, choose Insert-Module

5 Paste the code into the code window at right

6 Save the file and close the VBE.

Test the

code:

1 Hit Tools-Macro-Macros and double-click SortWorksheets

Ngày đăng: 09/11/2013, 01:11

TỪ KHÓA LIÊN QUAN

w