zoukankan      html  css  js  c++  java
  • [VBA]合并工作簿优化版

    Sub 合并工作簿数据()
    Dim arr
    Dim i As Integer, j As Integer, x As Integer
    Dim f As String, m As String, n As String
    ActiveSheet.Range("b4:y34").ClearContents
    f = ThisWorkbook.Path & ""
    l = f & "*.xls"
    m = Dir(l)
    Do While m <> ""
    If m <> ThisWorkbook.Name Then
    n = f & m
    Set wb = GetObject(n)
    For i = 4 To ActiveSheet.Range("a65536").End(xlUp).Row '行
    For j = 2 To ActiveSheet.Range("b3").End(xlToRight).Column - 2 Step 3 '列
    aa = Left(wb.Name, InStrRev(wb.Name, ".") - 1)
    If ActiveSheet.Cells(2, j).Value = aa Then
    arr = wb.Worksheets(1).Range("a1").CurrentRegion
    For x = 1 To UBound(arr)
    If ActiveSheet.Cells(i, 1) = arr(x, 1) Then
    ActiveSheet.Cells(i, j) = arr(x, 2)
    ActiveSheet.Cells(i, j + 1) = arr(x, 3)
    If VBA.IsNumeric(ActiveSheet.Cells(i, j + 1)) = False Then
    ActiveSheet.Cells(i, j + 2) = 0
    ElseIf ActiveSheet.Cells(i, j + 1) = 0 Then
    ActiveSheet.Cells(i, j + 2) = 0
    Else
    ActiveSheet.Cells(i, j + 2) = ActiveSheet.Cells(i, j) / ActiveSheet.Cells(i, j + 1)
    End If
    End If
    Next
    End If
    Next
    Next

    End If
    m = Dir
    Loop
    Set wb = Nothing
    End Sub

  • 相关阅读:
    jquery的data、attr、expando
    Vue-router导航问题
    函数声明与函数表达式
    Object.defineProperty方法
    移动端Web开发,ios下 input为圆角
    parseInt和map方法使用案例分析
    字符串处理常见函数
    ES6之Promise的基本用法
    浮动相关
    知识点拾遗
  • 原文地址:https://www.cnblogs.com/susuye/p/7250967.html
Copyright © 2011-2022 走看看