zoukankan      html  css  js  c++  java
  • VBA 格式化excel数据表 (数据分列)

    Sub ImportData()
    '
    ' Copy  Data from one workbook to the Current Workbook
    ' Place the macro file in the same folder as the source file
    '
        
        p = ThisWorkbook.Path & ""
        f = Dir(p & "*.xlsx")
        Application.ScreenUpdating = False
        thrn = ThisWorkbook.Sheets(1).Range("A100000").Row
        With ThisWorkbook.Sheets(1)
            .Range("A1:T" & thrn).ClearContents
        End With
        Do While f <> ""
            
                If f <> ThisWorkbook.Name Then
                    Set wb = GetObject(p & f)
                    With wb.Sheets(1)
                      rn = .Range("A100000").End(xlUp).Row
                      ThisWorkbook.Sheets(1).Range("A1:T" & rn).Value = .Range("A1:T" & rn).Value
                      MsgBox "Format Complete."
                    End With
                End If
                
            f = Dir
        Loop
        
    End Sub
    
    Sub Text_to_Columns()
    'Formatted Data Columns("A:A").Select Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _ Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _ :="|", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, _ 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12 _ , 1), Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 3), Array(17, 1), Array(18, 1), _ Array(19, 1), Array(20, 1)), DecimalSeparator:=".", ThousandsSeparator:=",", _ TrailingMinusNumbers:=True Columns("A:T").Select Selection.Copy End Sub Sub Copy_Back() ' ' Copy back the formatted data to the source file ' p = ThisWorkbook.Path & "" f = Dir(p & "*.xlsx") Application.ScreenUpdating = False thrn = ThisWorkbook.Sheets(1).Range("A100000").Row Do While f <> "" If f <> ThisWorkbook.Name Then Set wb = GetObject(p & f) With wb.Sheets(1) rn = .Range("A100000").End(xlUp).Row .Range("A1:T" & rn).ClearContents .Range("A1:T" & thrn).Value = ThisWorkbook.Sheets(1).Range("A1:T" & thrn).Value MsgBox "Complete." End With End If f = Dir Loop ThisWorkbook.Sheets(1).Range("A1:T" & thrn).ClearContents wb.Save 'Make sure the source file is already open End Sub Sub ExecConvert() ' 'Execute Macros ' Call ImportData Call Text_to_Columns Call Copy_Back End Sub

      

  • 相关阅读:
    算法图解——求Int整型数二进制中1的个数
    图解算法——句子逆序
    图解算法——反转字符串
    图解算法——整数倒置
    《图解算法》之狄克斯特拉算法
    图解算法——合并两个有序链表
    图解算法——括号匹配
    图解算法——两数之和
    #热烈庆祝我党成立100周年#
    jQuery全选反选
  • 原文地址:https://www.cnblogs.com/luoye00/p/11358409.html
Copyright © 2011-2022 走看看