Conditionally insert a duplicate row
Solved/Closed
acohen12
Posts
5
Registration date
Thursday June 6, 2013
Status
Member
Last seen
June 13, 2013
-
Jun 6, 2013 at 02:57 PM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Jun 17, 2013 at 10:32 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Jun 17, 2013 at 10:32 AM
Related:
- Conditionally insert a duplicate row
- Saints row 2 cheats - Guide
- How to insert a checkmark in word - Guide
- How to insert photo in word for resume - Guide
- Insert draft watermark in word on all pages - Guide
- How to insert @ in a laptop - Guide
5 responses
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Jun 13, 2013 at 10:37 AM
Jun 13, 2013 at 10:37 AM
Hi Acohen,
To do as you requested paste the following code in the big white field after selecting "View code" by right-clicking the sheets tab:
Best regards,
Trowa
To do as you requested paste the following code in the big white field after selecting "View code" by right-clicking the sheets tab:
Private Sub Worksheet_Change(ByVal Target As Range) If Intersect(Target, Range("C2:C100")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub If Target.Value = "Yes" Then Target.Offset(1, 0).EntireRow.Insert Range(Target.Offset(0, -2), Target.Offset(0, -1)).Copy Target.Offset(1, -2) End If End Sub
Best regards,
Trowa
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Jun 10, 2013 at 10:33 AM
Jun 10, 2013 at 10:33 AM
Hi Acohen,
A7: =IF(C6="Yes",A6,"")
B7: =IF(C6="Yes",B6,"")
Drag these two formula's down.
If C6 is "No" you can just overwrite the formula's.
Of course a macro can be written for you if you desire, but the formula's should suffice.
Best regards,
Trowa
A7: =IF(C6="Yes",A6,"")
B7: =IF(C6="Yes",B6,"")
Drag these two formula's down.
If C6 is "No" you can just overwrite the formula's.
Of course a macro can be written for you if you desire, but the formula's should suffice.
Best regards,
Trowa
acohen12
Posts
5
Registration date
Thursday June 6, 2013
Status
Member
Last seen
June 13, 2013
Jun 10, 2013 at 03:59 PM
Jun 10, 2013 at 03:59 PM
Thanks TrowaD, but I apologize because I should have noted that there will be rows beyond 6 and 7 with data already filled in, so I would not be able to drag down.
I would like it to insert a new row automatically if I put "Yes" in column C, as well as copy and past column A and B into the new row.
Is that too complicated?
I really appreciate the help.
I would like it to insert a new row automatically if I put "Yes" in column C, as well as copy and past column A and B into the new row.
Is that too complicated?
I really appreciate the help.
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Jun 11, 2013 at 10:19 AM
Jun 11, 2013 at 10:19 AM
Not at all Acohen, I'm just trying to look for the easiest solution.
Here is the code:
Run the code when you have selected a single cell in column C.
To create a shortcut, goto top menu > Extra > Macro > Macro's (or Alt+F8).
In the small window that pops up goto options and enter your short-cut combi.
Best regards,
Trowa
Here is the code:
Sub test() If ActiveCell.Value = "Yes" Then ActiveCell.Offset(1, 0).EntireRow.Insert Range(ActiveCell.Offset(0, -2), ActiveCell.Offset(0, -1)).Copy ActiveCell.Offset(1, -2) End If End Sub
Run the code when you have selected a single cell in column C.
To create a shortcut, goto top menu > Extra > Macro > Macro's (or Alt+F8).
In the small window that pops up goto options and enter your short-cut combi.
Best regards,
Trowa
Didn't find the answer you are looking for?
Ask a question
acohen12
Posts
5
Registration date
Thursday June 6, 2013
Status
Member
Last seen
June 13, 2013
Jun 11, 2013 at 06:04 PM
Jun 11, 2013 at 06:04 PM
Very nice. Is there a line of code that can be input that will automatically run the macro as soon as Yes entered, instead of using a shortcut key each time?
Jun 13, 2013 at 06:45 PM
Jun 17, 2013 at 10:32 AM
The way I can recreate the error is by protecting the sheet (except column C), thus prohibiting rows to be inserted.
So please check if rows can be inserted.
Otherwise post your file, for closer inspection, using a filesharing site like:
www.speedyshare.com
or
ge.tt
Be carefull with personal info.
Best regards,
Trowa