Extracting Data

dbnfl

Board Regular
Joined
Aug 11, 2019
Messages
59
Hello,

I need to adjust code below that it will always return a match if the following "Ok to Book" "Slotted" "Delivery Pending" are found in column 3 of my data Sheet (Sheet1). I tried adding in line of code in Green, you can click search and screen will flick but will not return anything. If I remove added code it will work to search Job Status selection Reportsheet C3.

Any help would be greatly appreciated

Sub Planning_Extract_Data()

Dim datasheet As Worksheet
Dim reportsheet As Worksheet
Dim jobstatus As String
Dim jobstatus2 As String
Dim Agent As String
Dim jobtype As String
Dim finalrow As Integer
Dim i As Integer
Dim Ary As Variant

Set datasheet = Sheet1
Set reportsheet = Sheet5

jobstatus = LCase(reportsheet.Range("C3").Value)
Agent = LCase(reportsheet.Range("E3").Value)
jobtype = LCase(reportsheet.Range("G3").Value)


reportsheet.Range("B7:AA200").ClearContents

datasheet.Select
finalrow = Cells(Rows.Count, 2).End(xlUp).Row
For i = 2 To finalrow

'If datasheet.Cells(i, 3).Value = "Ok to Book" or "Slotted" or "Delivery Pending" Then (jobstatus)
If LCase(Cells(i, 3)) = jobstatus Or jobstatus = "" Then
If LCase(Cells(i, 5)) = Agent Or Agent = "" Then
If LCase(Cells(i, 4)) = jobtype Or jobtype = "" Then
Ary = Application.Index(Rows(i), 1, Array(2, 3, 5, 6, 8, 10, 16, 18, 19, 58, 59, 29, 51, 41, 42, 43, 44, 46, 47, 49, 35, 36, 37, 34, 57, 53))
reportsheet.Range("B200").End(xlUp).Offset(1, 0).Resize(, 26).Value = Ary
'End If
End If
End If
End If
Next i

reportsheet.Select

Range("C3").Select

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
It needs to be
VBA Code:
If Cells(i, 3).Value = "Ok to Book" or Cells(i, 3).Value ="Slotted" or Cells(i, 3).Value ="Delivery Pending"
 
Upvote 0
A bit more compact alternative is

VBA Code:
If InStr(1, "|Ok to Book|Slotted|Delivery Pending|", "|" & datasheet.Cells(i, 3).Value & "|", 1) > 0 Then
 
Upvote 0
A bit more compact alternative is

VBA Code:
If InStr(1, "|Ok to Book|Slotted|Delivery Pending|", "|" & datasheet.Cells(i, 3).Value & "|", 1) > 0 Then

thank you for the reply. I used Michael M's line of code and its working nicely. I will also try your one as well.
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,397
Members
449,081
Latest member
JAMES KECULAH

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