Macro to copy a row from one worksheet to another based on a value

GAM055

New Member
Joined
Dec 10, 2015
Messages
3
Hi!

I am clueless about macros and would deeply appreciate your help.

Is it possible to have a macro copy a row from one worksheet and paste it in a new row in another worksheet based on what value is in a cell of that row in a specific column?

Let me give you an example of what I'm trying to do:

A B C D
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Date[/TD]
[TD]Project[/TD]
[TD]Event/Task[/TD]
[TD]Program[/TD]
[/TR]
[TR]
[TD]12/17/2015[/TD]
[TD]Presentation at conference[/TD]
[TD]T[/TD]
[TD]Other[/TD]
[/TR]
[TR]
[TD]12/23/2015[/TD]
[TD]Holiday party[/TD]
[TD]E[/TD]
[TD]Teachers[/TD]
[/TR]
[TR]
[TD]1/14/2016[/TD]
[TD]Refresher class[/TD]
[TD]E[/TD]
[TD]Students[/TD]
[/TR]
[TR]
[TD]1/19/2016[/TD]
[TD]Training of volunteers[/TD]
[TD]T[/TD]
[TD]Volunteers[/TD]
[/TR]
[TR]
[TD]2/3/2016[/TD]
[TD]PowerPoint on new techniques[/TD]
[TD]T[/TD]
[TD]Other[/TD]
[/TR]
</tbody>[/TABLE]











I have multiple worksheets. The first worksheet, the one shown above, is the "overview". The other worksheets are titled according to the Program categories (I have about 6 or 7) - see column D.

So, I would very much appreciate a macro that would copy rows in the first worksheet and copy each one to other specific workbooks matching the value in column D. For example, again referring to the table above, after I enter 2/3/2016, "PowerPoint on new techniques", "T", "Other"... then Excel's macro would copy that row and paste it in the workbook called "Other". (I also have workbooks titled "Teachers", "Students", "Volunteers" and more).

Hope I am making my request clear!

IF you are able to help by showing me the macro, would you be so kind to change the color of the values that I can change (so that I don't mess up the rest?)

THANK YOU,

John

P.S. Ideally the macro would run automatically every few minutes or at least each time I open the document in Excel 2007.
 

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 am clueless about macros and would deeply appreciate your help.

Is it possible to have a macro copy a row from one worksheet and paste it in a new row in another worksheet based on what value is in a cell of that row in a specific column?

Let me give you an example of what I'm trying to do:

A B C D
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Date[/TD]
[TD]Project[/TD]
[TD]Event/Task[/TD]
[TD]Program[/TD]
[/TR]
[TR]
[TD]12/17/2015[/TD]
[TD]Presentation at conference[/TD]
[TD]T[/TD]
[TD]Other[/TD]
[/TR]
[TR]
[TD]12/23/2015[/TD]
[TD]Holiday party[/TD]
[TD]E[/TD]
[TD]Teachers[/TD]
[/TR]
[TR]
[TD]1/14/2016[/TD]
[TD]Refresher class[/TD]
[TD]E[/TD]
[TD]Students[/TD]
[/TR]
[TR]
[TD]1/19/2016[/TD]
[TD]Training of volunteers[/TD]
[TD]T[/TD]
[TD]Volunteers[/TD]
[/TR]
[TR]
[TD]2/3/2016[/TD]
[TD]PowerPoint on new techniques[/TD]
[TD]T[/TD]
[TD]Other[/TD]
[/TR]
</tbody>[/TABLE]











I have multiple worksheets. The first worksheet, the one shown above, is the "overview". The other worksheets are titled according to the Program categories (I have about 6 or 7) - see column D.

So, I would very much appreciate a macro that would copy rows in the first worksheet and copy each one to other specific workbooks matching the value in column D. For example, again referring to the table above, after I enter 2/3/2016, "PowerPoint on new techniques", "T", "Other"... then Excel's macro would copy that row and paste it in the workbook called "Other". (I also have workbooks titled "Teachers", "Students", "Volunteers" and more).

Hope I am making my request clear!

IF you are able to help by showing me the macro, would you be so kind to change the color of the values that I can change (so that I don't mess up the rest?)

THANK YOU,

John

P.S. Ideally the macro would run automatically every few minutes or at least each time I open the document in Excel 2007.

do you mean another workbook or worksheet? The title says one worksheet to another but workbook is then stated
 
Upvote 0
Hi Gdesreu,

Thank you for pointing out my confusing language!

This is what I meant:

Is it possible to have a macro copy a row from one worksheet and paste it in a new row in another worksheet based on what value is in a cell of that row in a specific column?

Let me give you an example of what I'm trying to do:

A B C D
[TABLE="class: cms_table_grid, width: 500, align: left"]
<tbody>[TR]
[TD]Date[/TD]
[TD]Project[/TD]
[TD]Event/Task[/TD]
[TD]Program[/TD]
[/TR]
[TR]
[TD]12/17/2015[/TD]
[TD]Presentation at conference[/TD]
[TD]T[/TD]
[TD]Other[/TD]
[/TR]
[TR]
[TD]12/23/2015[/TD]
[TD]Holiday party[/TD]
[TD]E[/TD]
[TD]Teachers[/TD]
[/TR]
[TR]
[TD]1/14/2016[/TD]
[TD]Refresher class[/TD]
[TD]E[/TD]
[TD]Students[/TD]
[/TR]
[TR]
[TD]1/19/2016[/TD]
[TD]Training of volunteers[/TD]
[TD]T[/TD]
[TD]Volunteers[/TD]
[/TR]
[TR]
[TD]2/3/2016[/TD]
[TD]PowerPoint on new techniques[/TD]
[TD]T[/TD]
[TD]Other[/TD]
[/TR]
</tbody>[/TABLE]



I have multiple worksheets. The first worksheet, the one shown above, is the "overview". The other worksheets are titled according to the Program categories (I have about 6 or 7) - see column D.

So, I would very much appreciate a macro that would copy rows in the first worksheet and copy each one to other specific worksheets matching the value in column D. For example, again referring to the table above, after I enter 2/3/2016, "PowerPoint on new techniques", "T", "Other"... then Excel's macro would copy that row and paste it in the work
sheet called "Other". (I also have worksheets titled "Teachers", "Students", "Volunteers" and more).

Hope I am making my request clear!

IF you are able to help by showing me the macro, would you be so kind to change the color of the values that I can change (so that I don't mess up the rest?)

THANK YOU,

John

P.S. Ideally the macro would run automatically every few minutes or at least each time I open the document in Excel 2007.
 
Upvote 0
I'm not knowledgeable on how to have a script run every few moments. And having it run on workbook open would then mean it can only run when you open the workbook. Why not just create a button on your sheet and when you click the button the script will run.
Let me know if that option is possible and if so I will write you a script. If not someone else here at Mr. Excel will need to help you.
 
Upvote 0
If your willing to run the script with a Button or a shortcut key or from the Macro Recorder Box you can use this script.
You need to have a sheet Named "Overview" which is the sheet this script will be run from.
The rows will be copied over to the sheet named in column "D"

Your comment:
IF you are able to help by showing me the macro, would you be so kind to change the color of the values that I can change (so that I don't mess up the rest?)
There is no part of the script you need to change.
Code:
Sub Copy_To_Sheet_In_Column_D()
Application.ScreenUpdating = False
Dim i As Integer
Dim Lastrow As Long
Dim Lastrowa As Long
Sheets("Overview").Activate
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row

    For i = 2 To Lastrow
        Lastrowa = Sheets(Cells(i, 4).Value).Cells(Rows.Count, "A").End(xlUp).Row + 1
        Rows(i).Copy Destination:=Sheets(Cells(i, 4).Value).Rows(Lastrowa)
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi,

THANK YOU so much for your help. Unfortunately I encountered an error: "Run-time error '9': Subscript out of range".

I clicked on Debug and got the following line was highlighted:

Lastrowa = Sheets(Cells(i, 4).Value).Cells(Rows.Count, "A").End(xlUp).Row + 1

Please help me. Thank you!
 
Upvote 0
The script looks in column ("D") for a sheet name and copies the row to that sheet.
Are you sure all the values are spelled exactly the same way your sheets are named?
If the value in column "D" reads "George" then you need to have a sheet named "George"
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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