TVP

# 哈洞数据处理公司日常数据处理工作必备代码

Sub DeleteWorksheet()

MsgBox "删除当前工作簿中的工作表sheet2"

Worksheets("sheet2").Delete

End Sub

Sub testWorksheetExists1()

Dim ws As Worksheet

If Not WorksheetExists(ThisWorkbook,"sheet1") Then

MsgBox "未找到该工作表", vbOKOnly

Exit Sub

End If

MsgBox "找到工作表"

Set ws =ThisWorkbook.Worksheets("sheet1")

End Sub

Function WorksheetExists(wb As Workbook, sName As String) As Boolean

Dim s As String

On Error GoTo ErrHandle

s = wb.Worksheets(sName).Name

WorksheetExists = True

Exit Function

ErrHandle:

WorksheetExists = False

End Function

Sub SortWorksheets1()

Dim bSorted As Boolean

Dim nSortedSheets As Long

Dim nSheets As Long

Dim n As Long

nSheets = Worksheets.Count

nSortedSheets = 0

Do While (nSortedSheets>

bSorted = True

nSortedSheets = nSortedSheets + 1

For n = 1 To nSheets - nSortedSheets

If StrComp(Worksheets(n).Name, Worksheets(n + 1).Name,vbTextCompare) > 0 Then

Worksheets(n + 1).Move Before:=Worksheets(n)

bSorted = False

End If

Next n

Loop

End Sub

Sub SortWorksheets2()

'根据字母对工作表排序

Dim i As Long, j As Long

For i = 1 To Sheets.Count

For j = 1 To Sheets.Count - 1

If UCase\$(Sheets(j).Name) > UCase\$(Sheets(j +1).Name) Then

Sheets(j).Move After:=Sheets(j + 1)

End If

Next j

Next i

End Sub

Sub Delete_EmptySheets()

Dim sh AsWorksheet

For Each sh In ThisWorkbook.Worksheets

If Application.WorksheetFunction.CountA(sh.Cells) = 0Then

sh.Delete

End If

Next

End Sub

• 发表于:
• 原文链接http://kuaibao.qq.com/s/20180201A0IHMR00?refer=cp_1026
• 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 cloudcommunity@tencent.com 删除。

2023-10-02

2023-10-02

2023-10-02

2023-10-02

2023-10-02

2019-09-05

2023-10-02

Get大咖技术交流圈