Type mismatch error

katlong

New Member
Joined
Sep 6, 2018
Messages
9
Can anyone help me with the bold code that is a type mismatch below?

Sub Promise_Date_Change_Detector()
Application.ScreenUpdating = True
Dim WB As Workbook, WS As Worksheet
Dim c As Variant
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("U:\Public\All Customer Reports\All Customers Report 2018")
'Label Column Headers , "PO#", "Sales Order", "Line #", "Promise Date","file date"
Cells(5, 1).Value = "PO#"
Cells(5, 2).Value = "Sales Order"
Cells(5, 3).Value = "Line #"
Cells(5, 4).Value = "Promise Date"
'Build Input Box to Inquire as to PO in Question
PurchaseOrder = InputBox("What PO would you like information for?", "PO#?")
'Find Order Date in Latest file
LFile = Worksheets(1).Cells(2, 6).Value
Workbooks.Open (LFile)
k = Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row
For l = 2 To k
If Worksheets(1).Cells(l, 2).Value = PurchaseOrder Then
n = Worksheets(1).Cells(l, 14).Value
End If
Next l
o = n + 2
o = Format(o, "mm-dd-yyyy")
StrtFile = Application.WorksheetFunction.Concat(fldr, "", o, "am")
'Loop through all the files in the customers report folder and pull out the po info
x = ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
For c = StrtFile To LFile
Application.DisplayAlerts = False
If fso.GetExtensionName(wbFile.Name) = "xls" Then
Set WB = Workbooks.Open(wbFile.Path)
Set WS = Worksheets(1)
wsLR = WS.Cells(Rows.Count, 1).End(xlUp).Row

For Y = 2 To wsLR
If WS.Cells(Y, 2).Value = PurchaseOrder Then
Z = 6
WS.Cells(Y, 2).Copy Destination:=ThisWorkbook.Worksheets(1).Cells(Z, 1)
WS.Cells(Y, 3).Copy Destination:=ThisWorkbook.Worksheets(1).Cells(Z, 2)
WS.Cells(Y, 4).Copy Destination:=ThisWorkbook.Worksheets(1).Cells(Z, 3)
WS.Cells(Y, 21).Copy Destination:=ThisWorkbook.Worksheets(1).Cells(Z, 4)
Z = Z + 1
End If
x = x + 1
Next Y
End If
WB.Close (wbFile.Path)
Application.DisplayAlerts = True
Next c


'concatenate po and promise date
'remove duplicate rows
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
What is StrtFile?

StrtFile is the file in the folder I'm starting the loop with - it's variable based on date. I'm not starting at the beginning of the files in the folder. (there are nearly 800 files in the folder, so we want to loop through just the ones we need so I'm starting at date + 2 days from the date on the PO issued. Thanks for looking at this.

I'm thinking I may have to count how many files first? Thanks for any help
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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