Excel - VBA - Deleting rows in one sheet - should delete subsequent row in another sheet

umeshbanga

New Member
Joined
Sep 14, 2014
Messages
4
Hi

I have one workbook. there are two worksheets

In Sheet1 the first column (from row a5) have unique identifier (ID) for each row.

The content of these rows are copied across to sheet 2.

What I want is when I delete any particular row in Sheet 1 then it should delete the same row in sheet 2. The identifier would be the first column of sheet 1.

Is it possible? Can I please get a code for this?


Regards

Umesh Banga
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi,
Here I put macro for you. This macro is created by someone else, not me. But I don't remember his name. So, please thank him in your mind.
You may now how to run it.
Just for incase, the macro is for 4 Sheets, rename them before using, in accordance with your sheet names.
Htut




Option Explicit


'>>>> Modify these names to suit your sheet names <<<<
Const sSHEET1NAME = "Sheet1"
Const sSHEET2NAME = "Sheet2"
Const sSHEET3NAME = "Sheet3"
Const sSHEET4NAME = "Sheet4"
Sub DeleteLine()
' Delete a line in all staff worksheets
'
Dim rR As Range
Dim lR As Long
Dim wsWS As Worksheet
Dim mbaAnsw As VbMsgBoxResult

lR = ActiveCell.Row
mbaAnsw = MsgBox("Do you want to delete the employee: " & Cells(lR, 3) & " at current line?", _
Buttons:=vbOKCancel + vbQuestion, _
Title:="Delete Row " & Cells(lR, 2))

If mbaAnsw = vbOK Then
For Each wsWS In Worksheets
With wsWS
' only delete from the four staff sheets
If .Name = sSHEET1NAME Or .Name = sSHEET2NAME Or _
.Name = sSHEET3NAME Or .Name = sSHEET4NAME Then
.Cells(lR, 1).EntireRow.Delete
End If
End With
Next wsWS
End If
End Sub
 
Upvote 0
This does not work. The rows i have are in table format and both sheets are protected. I know how to unprotect them in code but how to select multiple ranges in two different sheets with two tables - cannot work it out.

Hi,
Here I put macro for you. This macro is created by someone else, not me. But I don't remember his name. So, please thank him in your mind.
You may now how to run it.
Just for incase, the macro is for 4 Sheets, rename them before using, in accordance with your sheet names.
Htut




Option Explicit


'>>>> Modify these names to suit your sheet names <<<<
Const sSHEET1NAME = "Sheet1"
Const sSHEET2NAME = "Sheet2"
Const sSHEET3NAME = "Sheet3"
Const sSHEET4NAME = "Sheet4"
Sub DeleteLine()
' Delete a line in all staff worksheets
'
Dim rR As Range
Dim lR As Long
Dim wsWS As Worksheet
Dim mbaAnsw As VbMsgBoxResult

lR = ActiveCell.Row
mbaAnsw = MsgBox("Do you want to delete the employee: " & Cells(lR, 3) & " at current line?", _
Buttons:=vbOKCancel + vbQuestion, _
Title:="Delete Row " & Cells(lR, 2))

If mbaAnsw = vbOK Then
For Each wsWS In Worksheets
With wsWS
' only delete from the four staff sheets
If .Name = sSHEET1NAME Or .Name = sSHEET2NAME Or _
.Name = sSHEET3NAME Or .Name = sSHEET4NAME Then
.Cells(lR, 1).EntireRow.Delete
End If
End With
Next wsWS
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,832
Messages
6,127,152
Members
449,366
Latest member
reidel

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