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:

HRJohn
HRPaul
HRDenver
HRAllan
ITHoyu
ITUkis
ITMo
ITKetdin

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>

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
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
7,721
Office Version
2007
Platform
Windows
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.
 

MARK858

Well-known Member
Joined
Nov 12, 2010
Messages
11,312
Office Version
365, 2010
Platform
Windows, Mobile
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?
 

Forum statistics

Threads
1,077,784
Messages
5,336,327
Members
399,076
Latest member
vullistax

Some videos you may like

This Week's Hot Topics

Top