2 open workbooks - find 1 delete from other

davie1982

Board Regular
Joined
Nov 19, 2007
Messages
170
Office Version
  1. 365
  2. 2019
Hiya again.

I like this forum as you can tell :P

I have 2 open workbooks. I've picked up the filenames in VB.

One of them is strRemitN

Another one is strStateM

In strRemit i have invoice numbers (OP/I123456) in column A.

in strStateM the invoice numbers are in column C

How would i go around, in VBA, to search for the first invoice number from strRemitN to strStateM, delete the row, then go to the next, all the way to the bottom?

To help with the stuff i've already got... i've worked out the last row.

Dim intLRow as integer
intLRow = Range("A65536").End(xlUp).Row

Can anyone either help me on this or point me in the right direction please?

Thanks.
 
Don't loop
Code:
Sub RemitCheck()
Dim lngLastRow As Long, i As Long

Dim str2ndWbName As String
Dim strWBName As String
strWBName = ActiveWorkbook.Name
str2ndWbName = Sheets("code").Range("A4").Formula
Workbooks.Open (Sheets("Code").Range("A1").Formula)

Windows(str2ndWbName).Activate
Application.ScreenUpdating = False
lngLastRow = Range("A65535").End(xlUp).Row

    Columns("H").Insert Shift:=xlToRight

    With Range("H5:H" & lngLastRow)
        .FormulaR1C1 = _
        "=IF(COUNTIF('[" & strWBName & "]Remittance'!C1,RC[-5])>0, 1, """")"
        On Error Resume Next
        .SpecialCells(-4123,1).EntireRow.Delete
    End With

    Columns("H").Delete Shift:=xlToLeft

    Application.ScreenUpdating = True
MsgBox prompt:="All invoice from the remit have been taken off of the Statement", _
        Title:="Complete"

End Sub
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
This one i've got here is instant, even with 1200 invoice numbers!

Code:
Application.Screenupdating = False
Dim lngPasteRow As Long
lngPasteRow = 2
    Columns("H").Insert Shift:=xlToRight
    With Range("H5:H" & lngLastRow)
        .FormulaR1C1 = _
        "=IF(COUNTIF('[" & strWBName & "]Remittance'!C1,RC[-5])>0, 1, """")"
    On Error Resume Next
    .SpecialCells(-4123, 1).EntireRow.Copy Sheets("Remitted").Rows(lngPasteRow)
    .SpecialCells(-4123, 1).EntireRow.Delete
    lngPasteRow = lngPasteRow + 1
    End With

    Columns("H").Delete Shift:=xlToLeft
Application.Screenupdating = True

Thanks for all your help guys, this way here i get no errors and all the invoices are kept in the remittance spreadsheet.
 
Upvote 0

Forum statistics

Threads
1,215,255
Messages
6,123,896
Members
449,132
Latest member
Rosie14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top