Search, Copy then Paste into a new tab

tezza

Active Member
Joined
Sep 10, 2006
Messages
375
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
  2. Web
Hi all,

Hope you can help.

Below is an image of data the our work program produces but it doesn't really do what I need.

What I would like is as follows:

Step 1:
Copy the data into a new tab

Step 2:
Delete any rows that have dates/times in it that doesn't contain "Sickness Absence" in the Description (Col H)

I know some won't have sickness so there won't be any filled rows, but that's fine for the purpose I need.

Ultimately, I just need to see how many sickness days each person has, so if you have a better solution I'm all ears :)

Thank you


break.png




Thank you.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
try this:
VBA Code:
Sub test()
 Dim outarr()
 lastrow = Cells(Rows.Count, "A").End(xlUp).Row
 inarr = Range(Cells(1, 1), Cells(lastrow, 8))
 ReDim outarr(1 To lastrow, 1 To 8)
 indi = 1
 For i = 1 To lastrow
  If inarr(i, 8) = "Sickness Absence" Then
   For j = 1 To 8
    outarr(indi, j) = inarr(i, j)
   Next j
   indi = indi + 1
  End If
 Next i
 If indi > 1 Then
 Worksheets.Add
 Range(Cells(1, 1), Cells(indi - 1, 8)) = outarr
 Else
  MsgBox " Absence not found"
 End If
 
End Sub
 
Upvote 0
try this:
VBA Code:
Sub test()
 Dim outarr()
 lastrow = Cells(Rows.Count, "A").End(xlUp).Row
 inarr = Range(Cells(1, 1), Cells(lastrow, 8))
 ReDim outarr(1 To lastrow, 1 To 8)
 indi = 1
 For i = 1 To lastrow
  If inarr(i, 8) = "Sickness Absence" Then
   For j = 1 To 8
    outarr(indi, j) = inarr(i, j)
   Next j
   indi = indi + 1
  End If
 Next i
 If indi > 1 Then
 Worksheets.Add
 Range(Cells(1, 1), Cells(indi - 1, 8)) = outarr
 Else
  MsgBox " Absence not found"
 End If
 
End Sub
Hi, this removes ALL rows without Sickness Absence, which doesn't match my needs.

Delete any rows that have dates/times in it that doesn't contain "Sickness Absence" in the Description (Col H)

It only needs to remove the rows that have dates / times in.

I will however have another use for this initial code so thank you for that :)
 
Upvote 0
try this code which adds the check for the dates:
VBA Code:
Sub test()
 Dim outarr()
 lastrow = Cells(Rows.Count, "B").End(xlUp).Row
 inarr = Range(Cells(1, 1), Cells(lastrow, 8))
 ReDim outarr(1 To lastrow, 1 To 8)
 indi = 1
 For i = 1 To lastrow
  If (IsDate(inarr(i, 2)) And inarr(i, 8) = "Sickness Absence") Or Not (IsDate(inarr(i, 2))) Then
   For j = 1 To 8
    outarr(indi, j) = inarr(i, j)
   Next j
   indi = indi + 1
  End If
 Next i
 If indi > 1 Then
 Worksheets.Add
 Range(Cells(1, 1), Cells(indi - 1, 8)) = outarr
 Else
  MsgBox " Absence not found"
 End If
 
End Sub
 
Upvote 0
Solution
try this code which adds the check for the dates:
VBA Code:
Sub test()
 Dim outarr()
 lastrow = Cells(Rows.Count, "B").End(xlUp).Row
 inarr = Range(Cells(1, 1), Cells(lastrow, 8))
 ReDim outarr(1 To lastrow, 1 To 8)
 indi = 1
 For i = 1 To lastrow
  If (IsDate(inarr(i, 2)) And inarr(i, 8) = "Sickness Absence") Or Not (IsDate(inarr(i, 2))) Then
   For j = 1 To 8
    outarr(indi, j) = inarr(i, j)
   Next j
   indi = indi + 1
  End If
 Next i
 If indi > 1 Then
 Worksheets.Add
 Range(Cells(1, 1), Cells(indi - 1, 8)) = outarr
 Else
  MsgBox " Absence not found"
 End If
 
End Sub
That works great for dates.

Can we also add a check for times?
 
Upvote 0

Forum statistics

Threads
1,215,136
Messages
6,123,246
Members
449,093
Latest member
Vincent Khandagale

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