[EXCEL]巨集範例

Sub HCUP160P_AUTO()

'

' HCUP160P_AUTO 巨集

'


'

    Rows("1:19").Select ' 選取1-19row

    Range("A19").Activate

    Selection.Delete Shift:=xlUp '刪除選取的row

    

    

    Columns("A:AE").Select

    With ActiveWindow

        .SplitColumn = 0

        .SplitRow = 0

    End With

    Selection.UnMerge

    

    Cells.Select

    With Selection

        .WrapText = False

        .Orientation = 0

        .AddIndent = False

        .IndentLevel = 0

        .ShrinkToFit = False

        .ReadingOrder = xlLTR

        .MergeCells = False

    End With

    Rows("1:1").Select

    With ActiveWindow

        .SplitColumn = 0

        .SplitRow = 1

    End With

    ActiveWindow.FreezePanes = True

    

    

    Dim i As Long

    i = ActiveSheet.UsedRange.Rows.Count '取得現在工作表有幾個row

    Dim strD As String

    strD = "Z" + Str(i)

    strD = Replace(strD, " ", "")  '算出右下角最後一格

    

    '依照G欄做排序

    Columns("G:G").Select

    ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Clear

    ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Add Key:=Range("G1"), _

        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

    With ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort

        .SetRange Range("A2:" + strD) '排序範圍擴大

        .Header = xlNo

        .MatchCase = False

        .Orientation = xlTopToBottom

        .SortMethod = xlPinYin

        .Apply

    End With

    Columns("A:Z").EntireColumn.AutoFit '完成後自動欄寬

End Sub



沒有留言:

張貼留言

[DataSet Bug]無法啟用條件約束。一或多個資料列的值違反非 Null、唯一或外部索引鍵條件約束

在使用TableAdapter作Query時發生 1. 原因為有些資料欄位Query出來後為null值 但是該欄位在dbDataSet的屬性AllowDBNull為False 因此把該欄位(或乾脆把全部欄位屬性AllowDBNull改為True 2. maxLength 檢...