Open another workbook and delete row based on data entry on active workbook

Musto85

New Member
Joined
Mar 6, 2022
Messages
21
Platform
  1. Windows
Hi all

I am looking for a code to:

-Get the name entered in cell C4 of the workbook currently open (Data Entry)
-Then open workbook named “Reports” and look through the table on "Sheet1" in column A for the cell matching the value of C4
-When found delete entire row



I post the code below jusy as a reference, this adds data on workbook2 based on a data entry in workbook1.

Thanks in advance for your help!!!


VBA Code:
Dim wb1 As Workbook, wb2 As Workbook
Dim destSht As Worksheet, shSet As Worksheet

Dim Wind, Wind2 As Window

Set wb1 = ThisWorkbook
Set wb2 = Workbooks.Open("P:\Report\Structure\Reports.xlsm")
Set destSht = wb2.Worksheets("Sheet1")
Set Wind2 = Windows("Reports.xlsm")
Set Wind = Windows(ThisWorkbook.Name)

Wind.WindowState = xlMinimized

 With ThisWorkbook.Worksheets("Data_Entry")
 With .Range(.Range("H4:M4"), .Range("H4:M4").End(xlDown))
 
Wind2.WindowState = xlMinimized
                      
    destSht.Cells(destSht.Rows.Count, 1).End(xlUp).Offset(1).Resize(, 6).Value = .Value
        
        End With
        End With
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Give this a try:

VBA Code:
Sub DeleteRow()
    Dim entWB As Workbook, destWB As Workbook
    Dim entSht As Worksheet, destSht As Worksheet
    Dim destRow As Long
   
    Set entWB = ThisWorkbook
    Set entSht = entWB.Worksheets("Data_Entry")
    Set destWB = Workbooks.Open("P:\Report\Structure\Reports.xlsm")
    Set destSht = destWB.Worksheets("Sheet1")
   
    With Application
        destRow = .IfError(.Match(entSht.Range("C4"), destSht.Columns("A"), 0), 0)
    End With
   
    If destRow <> 0 Then destSht.Rows(destRow).Delete
       
End Sub
 
Upvote 0
Thanks Alex that works!

However if I use the same code but for data both to read (K15) and delete (Table Column "i" instead of "A") on the same sheet it doesn't work!
Can you see where I am wrong?
This is the code:

VBA Code:
Dim entWB As Workbook
Dim entSht As Worksheet
Dim destRow As Long
   
Set entWB = ThisWorkbook
Set entSht = entWB.Worksheets("Management")


With Application
    destRow = .IfError(.Match(entSht.Range("K15"), entSht.Columns("i"), 0), 0)
End With
   
If destRow <> 0 Then entSht.Rows(destRow).Resize(ColumnSize:=1).Delete
 
Upvote 0
I am unclear as to what you are trying to delete.
The original code looked for the value that was in C4 in Column A in a differrent workbook and sheet.
It then deleted the row is was found on.

Your code is looking for the value that is in K15 in Column I of the "same" sheet.
From your code I can't tell what you want it to on the row that matches K15.

Please clarify.
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

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