小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

VBA【常用案例】

 Excel實(shí)用知識(shí) 2022-03-09

【1】工作表批量另存為獨(dú)立的工作簿

Sub 工作表批量另存為獨(dú)立的工作簿()

    Dim oWK As Worksheet

    Dim oWB As Workbook

    Dim sPath As String

    Dim sName As String

    If MsgBox('現(xiàn)在開始將把各工作表獨(dú)立另存為工作簿文件,請?jiān)俅螜z查格式數(shù)據(jù)是否正確?', vbYesNo, '重要提示') = vbYes Then

        sPath = Excel.ThisWorkbook.Path

        Excel.Application.ScreenUpdating = False

        Excel.Application.DisplayAlerts = False

        For Each oWK In Excel.ThisWorkbook.Worksheets

            With oWK

                    '將工作表名稱作為工作簿的名稱保存

                    sName = .Name

                    .Copy

                    Set oWB = Excel.Application.ActiveWorkbook

                    oWB.SaveAs sPath & '\' & .Name, xlOpenXMLWorkbook

                    oWB.Close

            End With

        Next

        Excel.Application.ScreenUpdating = True

        Excel.Application.DisplayAlerts = True

        MsgBox '操作結(jié)束'

    End If

End Sub

【2】插入圖片批注

Sub 插入圖片批注()

Dim a

a = MsgBox('使用說明:1、請確認(rèn)您的圖片文件存在與此文件同一目錄下的名稱為pic的文件夾中。2、選中要添加圖片批注的單元格。')

If a = 1 Then

On Error Resume Next

Dim MR As Range

Dim Pics As String

For Each MR In Selection

  If Not IsEmpty(MR) Then

    MR.Select

    MR.AddComment

    MR.Comment.Visible = False

    MR.Comment.Text Text:=''

    MR.Comment.Shape.Fill.UserPicture PictureFile:=ActiveWorkbook.Path & '\pic\' & MR.Value & '.jpg'

End If

Next

End If

End Sub

[3]行列轉(zhuǎn)換

Sub 行轉(zhuǎn)列()Dim i As Long, j As Long, k As LongDim m As Long, n As LongDim arr, brr, tOn Error GoTo last t = Timer Application.ScreenUpdating = False Worksheets('【行】數(shù)據(jù)').Activate Worksheets('【行】數(shù)據(jù)').AutoFilterMode = False Worksheets('【行】數(shù)據(jù)').Rows('1:1').AutoFilter ActiveWorkbook.Worksheets('【行】數(shù)據(jù)').AutoFilter.Sort.SortFields.Add Key:=Range( _ 'A1'), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _ xlSortNormal With ActiveWorkbook.Worksheets('【行】數(shù)據(jù)').AutoFilter.Sort .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Worksheets('【行】數(shù)據(jù)').AutoFilterMode = False Worksheets('【列】數(shù)據(jù)').Rows('1:1048576').ClearContents i = 2 m = Worksheets('【行】數(shù)據(jù)').Cells(1, 1).CurrentRegion.Columns.Count n = WorksheetFunction.CountA(Worksheets('【行】數(shù)據(jù)').Range(Cells(1, 2), Cells(WorksheetFunction.CountA(Worksheets('【行】數(shù)據(jù)').Columns('A:A')), m))) If n <= 1048580 Then '判斷是否超出excel表的行數(shù) ReDim arr(1 To n, 1 To 2) brr = Worksheets('【行】數(shù)據(jù)').Cells(1, 1).CurrentRegion.Value For j = 2 To UBound(brr) For k = 1 To UBound(brr, 2) If Len(brr(j, k)) = 0 Then Exit For If k = 1 Then arr(i, 1) = brr(j, 1) k = k + 1 arr(i, 2) = brr(j, k) Else i = i + 1 arr(i, 1) = arr(i - 1, 1) arr(i, 2) = brr(j, k) End If Next k i = i + 1 Application.StatusBar = '正在處理數(shù)據(jù):' & j & '行/' & k - 1 & '列' Next j Worksheets('【列】數(shù)據(jù)').Rows('1:1048576').ClearContents arr(1, 1) = Worksheets('【行】數(shù)據(jù)').Cells(1, 1).Value arr(1, 2) = Worksheets('【行】數(shù)據(jù)').Cells(1, 2).Value Worksheets('【列】數(shù)據(jù)').Cells(1, 1).Resize(i, 2) = arr Worksheets('【列】數(shù)據(jù)').Activate Application.StatusBar = '處理完成!' Erase arr Erase brr Else MsgBox '行轉(zhuǎn)換成列后的數(shù)據(jù)將超出Excel表行數(shù)限制!' Exit Sub End If Application.ScreenUpdating = True MsgBox '共用時(shí):' & Round(Timer - t, 3) & ' s'last:End Sub

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多