Copy cell if another cell contains YES

BravoBravoAu

Board Regular
Joined
Nov 8, 2011
Messages
63
Office Version
  1. 2016
Platform
  1. Windows
G'day all. I posted on here a month or two back about this issue and couldn't get the solution to work as intended, so I'm dusting off and trying again. I researched 'copy row to new workbook' but the trick is I don't want all information from Sheet 1 on Sheet 2.

I have two sheets:
1. Sheet 1 contains all details about employees including personal information. Column M is whether the employee is 'active' with a YES/NO drop list.
2. Sheet 2 contains a phone list that is widely available and can't include personal information. For active employees (eg those who have YES in Sheet1, column M), I would like SOME details copied into Sheet 2.

When employees are changed to inactive (eg those who have 'NO' in Sheet1, column M), I'm looking for them to 'disappear' from Sheet2 and the results adjust so there are no row spaces. Sheet1 wont have information removed.

For example:

Worksheet 2
Employee NameEmployee NumberPosition TitlePhone numberDesk LocationEmail address
(Copied data from Worksheet1, column A)
(Copied data from Worksheet1, column B)
(Copied data from Worksheet1, column D)
(Copied data from Worksheet1, column G)
(Copied data from Worksheet1, column E)
(Copied data from Worksheet1, column H)
 
Hi, After pasting the code on Sheet1, change the Value in Column L to No.

Corresponding record will be removed from Sheet2.

Meanwhile, after pasting the code what's your expectation ?
Apologies @Saurabhj - you did mention that. Got it, that performs as required. Thank you so much for your help!
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi, I think the issue is with how you are pasting the sheet change, so I will attempt to explain below, I have also put a working version on my Google Drive for you to download, it now removes records from sheet 3 too, because sequentially they will be on the same row as sheet 2, so I was mistaken in the assumption that the Employee Number was needed for this, my apologies for that.

Sheet 1 Code

Right click Sheet 1 in the vba window & select view code.

1.png

In the left dropdown at the top select worksheet

2.png

In the right dropdown at the top select change

3.png

Underneath Private Sub Worksheet_Change(ByVal Target As Range) but before End Sub paste

With Sheets("Sheet1")
If Not Intersect(Target, Range("L:L")) Is Nothing Then
If Target = "No" Then
Call Del_Inactive
ElseIf Target = "Yes" Then
Call TransferData
End If
End If
End With

5.png

I hope that helps.
 
Upvote 0
Hi, After pasting the code on Sheet1, change the Value in Column L to No.

Corresponding record will be removed from Sheet2.

Meanwhile, after pasting the code what's your expectation ?
Two other minor follow-up questions please @Saurabhj:
1. If I needed to change which column refers to active (YES/NO) from Column L to Column M, do I just need to update the range - 'If Not Intersect(Target, Range("L:L")) Is Nothing Then' or does the next line of code also need updating as well? I'm not sure what the enpNo line does...

2. If I require additional rows from Sheet1 to Sheet2, do I just need to update the range to add the relevant column - '.Range("J" & nextRow) = Sheets("Sheet1").Range("J" & Target.Row)'?
 
Upvote 0
1. Yes, change the range.

VBA Code:
If Not Intersect(Target, Range("M:M")) Is Nothing Then

2. If you added new rows in Sheet 1, if you add/ change column value to YES, row will be added to Sheet2 automatically. For this you don't need to change the code.

3. If you are adding extra column in Sheet 1 and corresponding value in Sheet 2 then you need to change the code.
VBA Code:
[I]'.Range("J" & nextRow) = Sheets("Sheet1").Range("J" & Target.Row)[/I]'

Hope it clarifies.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

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