gpt4 book ai didi

excel - VBA:我得到 "object variable or with block variable not set"

转载 作者:行者123 更新时间:2023-12-04 20:23:22 24 4
gpt4 key购买 nike

所以这是我的代码:

Option Explicit
Sub Check_Transactions2()
Dim QrtID() As Range
Dim Missing() As Range
Dim a, b As Range
Dim w, x, p, r As Variant
Dim i, iRw As Integer

Application.ScreenUpdating = False

r = Worksheets("Transac Check").Range("D1").Value

i = 0
Set b = Worksheets(r).Range("H4:H" & Worksheets(r).Range("I1"))
For Each x In b
i = i + 1
ReDim Preserve QrtID(1 To i)
QrtID(i) = x.Value
Next x

i = 0
For Each p In QrtID
If Application.WorksheetFunction.CountIf(Worksheets("Transactions").Range("W4:W" & Worksheets("Transactions").Range("X1").Value), p.Value) = 0 Then
i = i + 1
ReDim Preserve Missing(1 To i)
Missing(i) = p.Value
End If
Next p

For iRw = LBound(Missing) To UBound(Missing)
Worksheets("Transac Check").Cells(iRw + 1, 15).Value = Missing(iRw)
Next iRw

Application.ScreenUpdating = True

End Sub
当我到达线路时
    QrtID(i) = x.Value
我收到“对象变量或未设置 block 变量”错误,我真的不知道为什么。将不胜感激任何帮助。

最佳答案

检查交易 2

Option Explicit

Sub Check_Transactions2()

Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code

Dim cws As Worksheet: Set cws = wb.Worksheets("Transactions")
Dim dws As Worksheet: Set dws = wb.Worksheets("Transac Check")

Dim sName As String: sName = dws.Range("D1").Value
Dim sws As Worksheet: Set sws = wb.Worksheets(sName)
Dim srg As Range: Set srg = sws.Range("H4:H" & sws.Range("I1").Value)
Dim Data As Variant: Data = srg.Value

Dim i As Long, k As Long
For i = 1 To UBound(Data, 1)
If Application.WorksheetFunction.CountIf( _
cws.Range("W4:W" & cws.Range("X1").Value), Data(i, 1)) = 0 Then
k = k + 1
Data(k, 1) = Data(i, 1)
End If
Next i

dws.Range("O2").Resize(k).Value = Data

End Sub

关于excel - VBA:我得到 "object variable or with block variable not set",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66608360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com