Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 289|回复: 0

宏运行报错13

[复制链接]
发表于 2024-2-23 09:57 | 显示全部楼层 |阅读模式
Sub gonghuoshang()
Dim arr As Variant
Dim brr As Variant
Dim crr As Variant
Dim wb As Workbook
Dim wb1 As Workbook

t = Timer

s = "供货商.xlsx"
m = "C:\Users\admin021\Desktop" \ "+ s"

Set wb = Workbooks.Open(m)
Set shb = wb.Sheets(1)

k = shb.Range("a1000000").End(xlUp).Row

arr = shb.Range("a1:b" & k)

For i = k To 2 Step -1
    If shb.Range("a" & i) = "" Then
        shb.Range("a" & i).EntireRow.Delete
    End If
Next

k = shb.Range("a1000000").End(xlUp).Row

arr = shb.Range("a1:b" & k)

For i = 1 To k
    arr(i, 1) = Trim(arr(i, 1))
    arr(i, 1) = Replace(arr(i, 1), Chr(10), "")
Next

shb.Range("a1").Resize(k, 2) = arr

With ActiveWorkbook.Sheets(1)
    Set d = CreateObject("scripting.dictionary")
    r = .Cells(Rows.Count, 1).End(xlUp).Row
    ar = .Range("a1:b" & r)
    For i = 2 To UBound(ar)
        If Trim(ar(i, 1)) <> "" Then
            If Not d.exists(Trim(ar(i, 1))) Then
                d(Trim(ar(i, 1))) = ar(i, 2)
            Else
               d(Trim(ar(i, 1))) = d(Trim(ar(i, 1))) & "," & ar(i, 2)
            End If
        End If
    Next i
    rs = .Cells(Rows.Count, 5).End(xlUp).Row + 2
    .Range("e2:f" & rs) = Empty
    .[e2].Resize(d.Count, 2) = Application.Transpose(Array(d.keys, d.items))
End With



End Sub


但是在旧版就能使用,请问是什么原因



您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-29 15:41 , Processed in 0.191145 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表