Move records to different sheet based on criteria

oxygn

New Member
Joined
May 24, 2010
Messages
25
Hi guys,

I have a sheet with following data:
Item nameSheet
Subject 11
Subject 22
Subject 33
Subject 44
Subject 51,2,3
Subject 61,4
Subject 74
Subject 81,3,4
Subject 92,3
Subject 103
Subject 112
Subject 121
Subject 131
Subject 141

<colgroup><col><col></colgroup><tbody>
</tbody>
Column A lists all the courses, column b lists the sheets a course needs to go to.

The output sheets are named Course 1.... 4

So a sample output for Course 1 (sheet) will look like:
Course
Subject 1
Subject 5
Subject 6
Subject 8
Subject 12
Subject 13
Subject 14
NOTE:
a.
all course graduation requirements, documenting course details and terminal objectives;
b.all instructor course packages, including all course syllabi, Training Materials, Training aids and instructors notes and guides;
c.all Training delivery plans;
d.all manufacturers’ handbooks used in the delivery of Training;
e.all student study guides and workbooks;
f.all Training progress test and graduation specifications; and
g.all Training evaluation requirements and requirements for testing student achievement

<colgroup><col><col span="12"></colgroup><tbody>
</tbody>
Please note that notes section must not be over written.

I think I can move it one sheet, but I cannot think of a way to identify all the sheets listed in the cell.

Here is a link to excel workbook:
Droplr • Temp Sheet.xlsm

Thanks all,
Cheers
Kunal

<colgroup><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi Kunal,

I have a sorta clunky vba solution if you are willing.

Requires three named ranges and two helper columns on the List sheet.

Want to give it a go?

Regards,
Howard
 
Upvote 0
On your List sheet in the Sheet column you have some cells with multiple sheets, 1, 2, 3.
In those rows move the 2 to the next column and the 3 to the next and the same for the other few that have multiple sheet numbers. So that you have three columns with single digits and many blanks in the second and third.
Assuming the column labeled Sheets is col B select as many cell in that column as needed to cover the entries and name it ColB, select the same number of cell in C and name it ColC and same with col D. Columns C and D have just a few entries as you see.

Paste this code in the List sheet vba module and run it.

Code:
Option Explicit
Sub DataA()
Dim i As Variant
Dim ColB As Range
Dim ColC As Range
Dim ColD As Range
Dim c As Range
Application.ScreenUpdating = False
  For Each c In Range("ColB")
    If c.Value = 1 Then
      c.Offset(, -1).Copy
      Sheets("Course 1").Range("A20").End(xlUp) _
         .Offset(1, 0).PasteSpecial
    End If
    
    If c.Value = 2 Then
      c.Offset(, -1).Copy
      Sheets("Course 2").Range("A20").End(xlUp) _
         .Offset(1, 0).PasteSpecial
    End If
    
    If c.Value = 3 Then
      c.Offset(, -1).Copy
      Sheets("Course 3").Range("A20").End(xlUp) _
         .Offset(1, 0).PasteSpecial
    End If
    
    If c.Value = 4 Then
      c.Offset(, -1).Copy
      Sheets("Course 4").Range("A20").End(xlUp) _
         .Offset(1, 0).PasteSpecial
    End If
    
    
  Next
  
  For Each c In Range("ColC")
    If c.Value = 1 Then
      c.Offset(, -2).Copy
      Sheets("Course 1").Range("A20").End(xlUp) _
         .Offset(1, 0).PasteSpecial
    End If
    
    If c.Value = 2 Then
      c.Offset(, -2).Copy
      Sheets("Course 2").Range("A20").End(xlUp) _
         .Offset(1, 0).PasteSpecial
    End If
    
    If c.Value = 3 Then
      c.Offset(, -2).Copy
      Sheets("Course 3").Range("A20").End(xlUp) _
         .Offset(1, 0).PasteSpecial
    End If
    
    If c.Value = 4 Then
      c.Offset(, -2).Copy
      Sheets("Course 4").Range("A20").End(xlUp) _
         .Offset(1, 0).PasteSpecial
    End If
    
  Next
  
  For Each c In Range("ColD")
    If c.Value = 1 Then
      c.Offset(, -3).Copy
      Sheets("Course 1").Range("A20").End(xlUp) _
         .Offset(1, 0).PasteSpecial
    End If
    
    If c.Value = 2 Then
      c.Offset(, -3).Copy
      Sheets("Sheet2").Range("A20").End(xlUp) _
         .Offset(1, 0).PasteSpecial
    End If
    
    If c.Value = 3 Then
      c.Offset(, -3).Copy
      Sheets("Course 3").Range("A20").End(xlUp) _
         .Offset(1, 0).PasteSpecial
    End If
    
    If c.Value = 4 Then
      c.Offset(, -3).Copy
      Sheets("Course 4").Range("A20").End(xlUp) _
         .Offset(1, 0).PasteSpecial
    End If
    
  Next
  
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub

Regards,
Howard
 
Upvote 0
Thanks Howard, that worked. I made a slight modification to suit my needs.

Cheers,
K :eek:
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,926
Members
449,479
Latest member
nana abanyin

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