Sub SortTable(top, left, right, bottom, Col)
    Range(Cells(top, left), Cells(bottom, right)).Select
    Selection.Sort Key1:=Columns(Col), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
        :=xlPinYin
End Sub
MAIL TO [email protected]

解决方案 »

  1.   

    还有如下代码
    Sub SetWidth(ColIndex, B_Row, E_Row, MinW)
        Dim temp_Width, temp_ChrWidth, tempLen As Double
        Dim tempCon As String
        Dim charVal As Integer
        Dim flag As Boolean
        Dim strlen As Integer
        Dim K As Integer
        
        
        
        temp_Width = MinWidth
        If MinW > MinWidth Then
            temp_Width = MinW
        End If
        
        For I = B_Row To E_Row
            temp_ChrWidth = Cells(I, ColIndex).Font.Size / 11
            If IsNull(temp_ChrWidth) Then
                temp_ChrWidth = 9
            End If
            tempCon = Format(Cells(I, ColIndex))
            flag = False
            For K = 1 To Len(tempCon)
               charVal = Asc(Mid(tempCon, K, 1))
               If charVal = 10 Then
                    flag = True
                    GoTo 100:
               End If
            Next
    100:
            If flag = True Then
                strlen = K
            Else
                strlen = Len(tempCon)
            End If
            tempLen = strlen * temp_ChrWidth
            If tempLen > temp_Width And tempLen < MaxWidth Then
                temp_Width = tempLen
            End If
        Next
        Columns(ColIndex).ColumnWidth = temp_Width
    End Sub