Extract data from a table and put in another table

jsambrook

Board Regular
Joined
Feb 1, 2010
Messages
214
I have a list of staff with hours worked. On one row it has NT and the row below it has OT. Some are agency staff and some are Permanent. I want to take all the permanent staff and insert them in a new table on another sheet. They are not ordered by type of staff and there are two rows that need extracting.

I dont know if it needs a Macro or I can do it with a formula. There may be more staff added and some removed over time and I want to just have everything slot into place.

Anyone got any ideas how to do it?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
jsambrook,

What version of Excel are you using?

You will generally get much more help (and faster) in this forum if you can post your small samples (what you have and what you expect to achieve) directly in the forum.

To attach screenshots, see below in my Signature block: Post a screen shot with one of these:
 
Upvote 0
Hiker95

I'm using Excel 2003. I cant install anything on this machine so will just have to describe it a bit better.

Row 1 and 2 contains normal and overtime respectively for permanent staff no1. Row 4 and 5 contains Normal and overtime respectively for agency staff no1.
Row 7 and 8 contains Normal and overtime respectively for agency staff no1.
Row 10 and 11 contains normal and overtime respectively for permanent staff no1.

From this I want to take just the permanent staff and put them in a new tab so they have the same format. I have tried using an auto filter and it does the job fine, until I put the protection back on the worksheet and then it wont let me select the drop down list, even though these cells aren't locked.
 
Upvote 0
jsambrook,

If you are not able to give us screenshots, see below in my Signature block: You can upload your workbook to Box Net, and provide us with a link to your workbook.
 
Upvote 0
jsambrook,


The macro will create a new worksheet Permanent, or if the worksheet already exists, the macro will first clear worksheet Permanent, and then copy the data from Sheet1. If you do not want this to happen, I can change the macro.


Sample raw data in worksheet Sheet1 (only showing 19 of the 96 rows of data for brevity):


Excel Workbook
ABCDEFGHIJK
1Aidan BrowneNTPermanentPermanentNTRawdon4700000
2overtime hoursOTPermanentPermanentOT700000
3
4Jerry CarterNTPermanentPermanentNTBaildon52.500000
5overtime hoursOTPermanentPermanentOT12.500000
6
7Karen HawleyNTPermanentPermanentNTBaildon3100000
8
9Peter DuerdenNTPermanentPermanentNTBaildon49.7500000
10overtime hoursOTPermanentPermanentOT9.7500000
11
12Darrell FirthNTPermanentPermanentNTBaildon00000
13overtime hoursOTPermanentPermanentOT2.2500000
14
15Roy GillinghamNTPermanentPermanentNTBaildon50.500000
16overtime hoursOTPermanentPermanentOT10.500000
17
18Jemima HardyNTPermanentPermanentNTRawdon404040404040
19
Sheet1





After the macro in a new worksheet Permanent (only showing 19 rows of the 60 for brevity):


Excel Workbook
ABCDEFGHIJK
1Aidan BrowneNTPermanentPermanentNTRawdon4700000
2overtime hoursOTPermanentPermanentOT700000
3
4Jerry CarterNTPermanentPermanentNTBaildon52.500000
5overtime hoursOTPermanentPermanentOT12.500000
6
7Karen HawleyNTPermanentPermanentNTBaildon3100000
8
9Peter DuerdenNTPermanentPermanentNTBaildon49.7500000
10overtime hoursOTPermanentPermanentOT9.7500000
11
12Darrell FirthNTPermanentPermanentNTBaildon00000
13overtime hoursOTPermanentPermanentOT2.2500000
14
15Roy GillinghamNTPermanentPermanentNTBaildon50.500000
16overtime hoursOTPermanentPermanentOT10.500000
17
18Jemima HardyNTPermanentPermanentNTRawdon404040404040
19
Permanent





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub GetPermanent()
' hiker95, 07/27/2011
' http://www.mrexcel.com/forum/showthread.php?t=567205
Dim w1 As Worksheet, wP As Worksheet
Dim Area As Range, SR As Long, ER As Long, NR As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Sheet1")
If Not Evaluate("ISREF(Permanent!A1)") Then Worksheets.Add(After:=w1).Name = "Permanent"
Set wP = Worksheets("Permanent")
wP.UsedRange.Clear
For Each Area In w1.Range("A1", w1.Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
  With Area
    SR = .Row
    ER = SR + .Rows.Count - 1
    NR = wP.Range("A" & Rows.Count).End(xlUp).Offset(2).Row
    If wP.Cells(1, 1) = "" And wP.Cells(2, 1) = "" Then NR = 1
    If w1.Range("C" & SR) = "Permanent" Then
      If SR = ER Then
        wP.Range("A" & NR).Resize(, 11).Value = w1.Range("A" & SR & ":K" & SR).Value
      Else
        wP.Range("A" & NR).Resize(ER - SR + 1, 11).Value = w1.Range("A" & SR & ":K" & ER).Value
      End If
    End If
  End With
Next Area
wP.UsedRange.Columns.AutoFit
wP.Activate
Application.ScreenUpdating = True
End Sub


Then run the GetPermanent macro.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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