2

So this is my code:

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

When I get to the line

    QrtID(i) = x.Value

I receive the "object variable or with block variable not set" error, and I can't really figure out why. Would appreciate any help.

2
  • 4
    change Dim QrtID() As Range to Dim QrtID() As VAriant Commented Mar 12, 2021 at 23:06
  • or Set QrtID(i) = x Commented Mar 12, 2021 at 23:06

1 Answer 1

1

Check Transactions 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
Sign up to request clarification or add additional context in comments.

1 Comment

Ok thank you so much for this. It works perfectly!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.