首页 > 代码库 > 20170501xlVBA销售订单整理一行转多行
20170501xlVBA销售订单整理一行转多行
Sub NextSeven_CodeFrame() Application.ScreenUpdating = False Application.DisplayAlerts = False Application.Calculation = xlCalculationManual Application.StatusBar = ">>>>>>>>程序正在运行>>>>>>>>" On Error GoTo ErrHandler Dim StartTime, UsedTime As Variant StartTime = VBA.Timer ‘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Dim Wb As Workbook Dim Sht As Worksheet Dim oSht As Worksheet Dim Rng As Range ‘Dim Arr As Variant Dim Arr() Dim EndRow As Long Const HEAD_ROW As Long = 1 Const SHEET_NAME As String = "原始订单" Const START_COLUMN As String = "A" Const END_COLUMN As String = "O" Dim i As Long, j As Long, k As Long Dim N As Long Const OTHER_HEAD_ROW As Long = 1 Const OTHER_SHEET_NAME As String = "整理订单" Const OTHER_START_COLUMN As String = "A" Const OTHER_END_COLUMN As String = "O" ‘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ‘获取原始记录 Set Wb = Application.ThisWorkbook Set Sht = Wb.Worksheets(SHEET_NAME) With Sht EndRow = .Cells(.Cells.Rows.Count, 1).End(xlUp).Row Set Rng = .Range(.Cells(HEAD_ROW + 1, START_COLUMN), .Cells(EndRow, END_COLUMN)) ‘Arr = Rng.Value ReDim Arr(1 To Rng.Rows.Count, 1 To Rng.Columns.Count) With Rng For i = 1 To .Rows.Count For j = 1 To .Columns.Count Arr(i, j) = .Cells(i, j).Text Next j Next i End With End With ‘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ‘生成新记录 Dim brr() As String ReDim brr(1 To 15, 1 To 1) N = 0 For i = LBound(Arr) To UBound(Arr) Key = CStr(Arr(i, 2)) ‘判断Chr(10) If InStr(1, Key, Chr(10)) = 0 Then N = N + 1 ReDim Preserve brr(1 To 15, 1 To N) For j = 1 To 15 brr(j, N) = Arr(i, j) Next j Else crr = Split(Key, Chr(10)) For k = LBound(crr) To UBound(crr) N = N + 1 ReDim Preserve brr(1 To 15, 1 To N) If k = 0 Then For j = 1 To 15 If j = 2 Then brr(j, N) = crr(k) Else brr(j, N) = Arr(i, j) End If Next j Else brr(2, N) = crr(k) brr(14, N) = Arr(i, 14) brr(15, N) = Arr(i, 15) End If Next k End If Next i For i = LBound(brr, 2) To UBound(brr, 2) brr(14, i) = Replace(brr(14, i), "深圳号-顺丰国际小包挂号", "USPS") Next i ‘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Set oSht = Wb.Worksheets(OTHER_SHEET_NAME) With oSht .UsedRange.Offset(1).ClearComments .Range("A2").Resize(UBound(brr, 2), UBound(brr)).Value = http://www.mamicode.com/_"本次耗时:" & Format(UsedTime, "0.000秒"), vbOKOnly, "NextSeven Excel Studio" ErrorExit: Set Wb = Nothing Set Sht = Nothing Set Rng = Nothing Set oSht = Nothing Application.ScreenUpdating = True Application.DisplayAlerts = True Application.Calculation = xlCalculationAutomatic Application.StatusBar = False Exit Sub ‘>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ErrHandler: If Err.Number <> 0 Then MsgBox Err.Description & "!", vbCritical, "NextSeven Excel Studio " ‘Debug.Print Err.Description Err.Clear Resume ErrorExit End If End Sub
20170501xlVBA销售订单整理一行转多行
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。