2015年7月28日星期二

Excel VBA - Before Dataimport

Sub RomoveEmptyColumn()

    Dim IsEmpty As Boolean
   
    ro = getRowCount(0)
    co = getColumnCount(0)
   
    For c = co To 1 Step -1
        IsEmpty = True
        For r = 2 To ro
            'Cells(r, c).Select
            If Cells(r, c).Value <> "" Then
                IsEmpty = False
                r = ro
            End If
        Next r
       
        If IsEmpty = True Then
            Columns(c).Select
            Columns(c).Delete
        End If
    Next c
       
End Sub

Sub DataTidy()

    ro = getRowCount(0)
    For r = 2 To ro
        Cells(r, 2).Select
        Cells(r, 2).Value = "'" & Cells(r, 2).Value
    Next

    ro = getRowCount(0)
    For r = 2 To ro
        Cells(r, 2).Value = "'" & Cells(r, 2).Value
        Cells(r, 7).Value = "'" & Cells(r, 7).Value
        Cells(r, 12).Value = "'" & Cells(r, 12).Value
        Cells(r, 13).Value = "'" & Cells(r, 13).Value
        Cells(r, 26 + 4).Value = "'" & Cells(r, 26 + 4).Value
        Cells(r, 26 + 5).Value = "'" & Cells(r, 26 + 5).Value
        Cells(r, 26 + 16).Value = "'" & Cells(r, 26 + 16).Value
        Cells(r, 26 + 21).Value = "'" & Cells(r, 26 + 21).Value
        Cells(r, 26 + 22).Value = "'" & Cells(r, 26 + 22).Value
        Cells(r, 52 + 4).Value = "'" & Cells(r, 52 + 4).Value
        Cells(r, 52 + 14).Value = "'" & Cells(r, 52 + 14).Value
    Next

End Sub

沒有留言:

發佈留言