Copy sheet with same row values to another sheet

woodydapogi

New Member
Joined
Oct 30, 2019
Messages
1
Hi,

I'm a newbie when it comes to excel, to be honest all I know was the basic stuff, I just learned the word macro earlier this day from my boss, currently reading some of it. I was tasked to sort/clean output of data to our sheets, I would like to ask on how to copy the rows with the same values to another sheets.

i.e:

[TABLE="width: 128"]
<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64"]HR[/TD]
[TD="width: 64"]John[/TD]
[/TR]
[TR]
[TD]HR[/TD]
[TD]Paul[/TD]
[/TR]
[TR]
[TD]HR[/TD]
[TD]Denver[/TD]
[/TR]
[TR]
[TD]HR[/TD]
[TD]Allan[/TD]
[/TR]
[TR]
[TD]IT[/TD]
[TD]Hoyu[/TD]
[/TR]
[TR]
[TD]IT[/TD]
[TD]Ukis[/TD]
[/TR]
[TR]
[TD]IT[/TD]
[TD]Mo[/TD]
[/TR]
[TR]
[TD]IT[/TD]
[TD]Ketdin
[/TD]
[/TR]
</tbody>[/TABLE]

Those names with "HR" will be copied to "HR Sheet" and those names with "IT" will be copied to "IT Sheet"

Thanks and regards,

Woody Pogi
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi @woodydapogi, welcome to the forum!

If your data is like the following:

Sheet1
<table border="1" cellspacing="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:76.04px;" /><col style="width:76.04px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td><td >B</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td >Sheet</td><td >Name</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td >HR</td><td >John</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td >HR</td><td >Paul</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td >HR</td><td >Denver</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td >HR</td><td >Allan</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td >IT</td><td >Hoyu</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td >IT</td><td >Ukis</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >8</td><td >IT</td><td >Mo</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >9</td><td >IT</td><td >Ketdin</td></tr></table>

Run this macro:

Note: Change "Sheet1" to the name of your sheet with the data.

Code:
Sub [COLOR=#0000ff]Copy_sheet[/COLOR]()
  Dim c As Range, sh As Worksheet, ky As Variant
  Application.ScreenUpdating = False
  Set sh = Sheets("[B][COLOR=#ff0000]Sheet1[/COLOR][/B]")
  With CreateObject("scripting.dictionary")
     For Each c In sh.Range("A2", sh.Range("A" & Rows.Count).End(xlUp))
        If c.Value <> "" Then .Item(c.Value) = Empty
     Next c
     For Each ky In .Keys
        sh.Range("A1").AutoFilter 1, ky
        If Evaluate("ISREF('" & ky & "'!A1)") Then
          sh.AutoFilter.Range.Offset(1).EntireRow.Copy Sheets(ky).Range("A" & Rows.Count).End(xlUp)(2)
        End If
     Next ky
  End With
  sh.ShowAllData
  MsgBox "End"
End Sub

------------------------------------
HOW TO INSTALL MACROs
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (Copy_sheet) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0
What is the name of the source sheet? What columns is the data in post number 1 in? and what column are the names in post number 1 being pasted to?
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,118
Members
453,021
Latest member
Justyna P

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