Within a For Each loop - code below, I loop down Column V of a dimmed worksheet "wsr", so I assigned "v" as the range variable within Column V, so in essence it is a "For each v in ColV" situation. When a certain set of conditions is met for a given "v", I want to cut-and-paste the entire row to another worksheet.
So I store the address of the "v" as "vaddr", and then below in script attempt to use it to cut-and-paste the entire row to another worksheet. The variable "j" is incremented during the execution of the For Each loop. When I step through the code, the error below generates for the line immediately below it : "Run time error 5: Invalid procedure call or argument".
wsr.Range(vaddr).EntireRow.Cut wsc.Range(Cells(j & "A")) '(Part of the code below) The "vaddr" for example stored "$V$136" in one case.
So I store the address of the "v" as "vaddr", and then below in script attempt to use it to cut-and-paste the entire row to another worksheet. The variable "j" is incremented during the execution of the For Each loop. When I step through the code, the error below generates for the line immediately below it : "Run time error 5: Invalid procedure call or argument".
wsr.Range(vaddr).EntireRow.Cut wsc.Range(Cells(j & "A")) '(Part of the code below) The "vaddr" for example stored "$V$136" in one case.
VBA Code:
[/Dim wbm As Workbook, wbr As Workbook: Dim wsm As Worksheet, wsr As Worksheet, wsc As Worksheet:
Dim LastRowr As Long: Dim Match As Boolean: Dim ColV As Range, v As Range: Dim vaddr As String
Option Explicit
Public Sub Initialize()
Application.ScreenUpdating = False: Application.Calculation = xlManual: Application.EnableEvents = False
Set wbm = Workbooks("Recon Match-and-Clear Macro.xlsm")
Set wsm = wbm.Sheets("Macro")
Set wbr = Workbooks("LST_092019_25590000-25590200_MULTIPLE_ACCRUAL ROLL FORWARD TEMPLATE V1.0.xlsx")
Set wsr = wbr.Sheets("Open Items")
Set wsc = wbr.Sheets("Closed Items")
LastRowr = wsr.Cells(Rows.Count, 1).End(xlUp).Row
Process
Application.ScreenUpdating = True: Application.EnableEvents = True
End Sub
Public Sub Process()
Dim wsrrow As Range, WBSe As Variant, WBSeNext As Variant, Amt1 As Double, Amt2 As Double, i As Integer, j As Integer
j = 6 'The Header row of the Closed Items sheet
Set ColV = wsr.Range(Cells(8, 22).Address, Cells(LastRowr, 22).Address)
For Each v In ColV
'If Left(v, 4) = "US1-" Then
Set wsrrow = wsr.Range(Cells(v.Row, 1).Address, Cells(v.Row, 36).Address)
WBSe = v.Value
WBSeNext = v.Offset(1, 0)
If WBSeNext = WBSe Then
Amt1 = v.Offset(0, -3)
Amt2 = v.Offset(1, -3)
End If
If Amt2 = -(Amt1) Then
i = i + 1
vaddr = v.Address
wsr.Range(vaddr).EntireRow.Cut wsc.Range(Cells(j & "A"))
'.Range("A1").Cut Sheet2.Range("A1")
'wsr.Range(vaddr).Copy Destination:=wsc.Range(j & "A")
End If
'End If
Next
End Sub]