Extract only the information I need

-emma-

Board Regular
Joined
Jul 14, 2006
Messages
184
Office Version
  1. 365
Platform
  1. Windows
Hi,
I need to extract specific information from a data dump we get for work.
I am hoping that the more knowledgeable people out there can help me make this work to save me almost hours each day at work.

From the picture attached, the left is what I would be pasting into Tab 1, columns A-D and the information on the right is the outcome id like into Tab 2, again columns A-D.

I am attempting to gleam the start, end and lunch and breaks at a glance, which I can do with some manipulation but this takes up a lot of my time.

Some staff may have more than one lunch and break. There is always 2 blank spaces after data and there are 3 blank lines of data when someone doesn't work. I have tried to cover the majority of options that occur each day.

Any help on this would be appreciated

Thank you in advance :)
 

Attachments

  • Capture.JPG
    Capture.JPG
    207.5 KB · Views: 16

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.
This will do it, I've used single digit numbers rather than retyping all of the times but it will work the same with either.

I'll have another look later to see if I can shorten the formula a bit by making better use of LET or by using some other functions without compromising the results.
Mr excel 16.01.23.xlsm
ABCDEFGHI
1CodeStartEndCodeStartEnd
2Staff11Staff1Start1
3Staff112Staff1Break23
4Staff1Break23Staff1Lunch45
5Staff134Staff1Break67
6Staff1Lunch45Staff1End8
7Staff156Staff2Start1
8Staff1Break67Staff2Break23
9Staff178Staff2Lunch67
10Staff18Staff2End8
11Staff1Staff3Start1
12Staff1Staff3End2
13Staff21
14Staff212
15Staff2Break23
16Staff234
17Staff245
18Staff256
19Staff2Lunch67
20Staff278
21Staff28
22Staff2
23Staff2
24Staff31
25Staff312
26Staff32
27Staff4
28Staff4
29Staff4
30
Sheet7
Cell Formulas
RangeFormula
F2:I12F2=LET(a,IF((C2:C29="")*(D2:D29<>""),HSTACK(A2:A29,EXPAND("Start",ROWS(A2:A29),1,"Start"),D2:D29,EXPAND("",ROWS(A2:A29),1,"")),IF((C2:C29<>"")*(D2:D29=""),HSTACK(A2:A29,EXPAND("End",ROWS(A2:A29),1,"End"),EXPAND("",ROWS(A2:A29),1,""),C2:C29),A2:D29)),FILTER(a,INDEX(a,0,2)<>0))
Dynamic array formulas.
 
Upvote 0
Hi @-emma- ,

Fit in the macro, to the name of your sheets.
In tab2 sheet in columns C and D put the same time format that you have in tab1 sheet.

Try the following macro:
VBA Code:
Sub Extract_information()
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim a As Variant, b As Variant
  Dim i As Long, j As Long
  Dim ant As String
  Dim endhour As Variant
  
  Set sh1 = Sheets("Tab1")    'Fit to your sheet name
  Set sh2 = Sheets("Tab2")    'Fit to your sheet name
  
  a = sh1.Range("A2:D" & sh1.Range("A" & Rows.Count).End(3).Row + 1).Value
  ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
  
  sh2.Cells.ClearContents
  ant = a(1, 1)
  For i = 1 To UBound(a, 1) - 1
    If ant = a(i, 1) Then
      If a(i, 2) <> "" Then
        j = j + 1
        b(j, 1) = a(i, 1)
        b(j, 2) = a(i, 2)
        b(j, 3) = a(i, 3)
        b(j, 4) = a(i, 4)
      End If
    Else
      j = j + 1
      b(j, 1) = ant
      b(j, 2) = "End"
      b(j, 3) = ""
      b(j, 4) = endhour
      endhour = ""
      If a(i, 4) <> "" Then endhour = a(i, 4)
    End If
    
    If a(i, 2) = "" And a(i, 3) = "" And a(i, 4) <> "" Then
      j = j + 1
      b(j, 1) = a(i, 1)
      b(j, 2) = "Start"
      b(j, 3) = a(i, 4)
    End If
    
    ant = a(i, 1)
    If a(i, 4) <> "" Then endhour = a(i, 4)

  Next
  sh2.Range("A2").Resize(j, 4).Value = b
End Sub

NOTE XL2BB:
For the future, it would help greatly if you could give us the sample data in a form that we can copy to test with, rather that a picture.
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in
Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.


Example:
Dante Amor
ABCD
1CodeStartEnd
2Staff1Start10:32
3Staff1Break12:4513:00
4Staff1Lunch14:4915:24
5Staff1Break16:5818:31
6Staff1End18:31
7Staff2Start07:23
8Staff2Break09:0409:17
9Staff2Lunch13:0413:24
10Staff2End15:24
11Staff3Start07:55
12Staff3End15:49
Tab2
 
Upvote 0

Forum statistics

Threads
1,224,752
Messages
6,180,742
Members
452,996
Latest member
nelsonsix66

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