Loop type mismatch error

katlong

New Member
Joined
Sep 6, 2018
Messages
9
Trying to loop through multiple files in a folder. Keep getting run time error 13 type mismatch on the bold below. Can anyone help?
Rich (BB code):
Sub Promise_Date_Change_Detector()
Dim WB As Workbook, WS As Worksheets
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#?")
'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 Each wbFile In fldr.Files


    If fso.GetExtensionName(wbFile.Name) = "xls" Then
        Set WB = Workbooks.Open(wbFile.Path)
        Set WS = Worksheets("Foglio1")
        wsLR = WS.Cells(Rows.Count, 1).End(xlUp).Row
    
        For Y = 2 To wsLR
            If Cells(Y, 2).Value = PurchaseOrder Then
            Cells(Y, 2).Copy
            ActiveSheet.Cells(x, 1).Paste
            Cells(Y, 3).Copy
            ActiveSheet.Cells(x, 2).Paste
            Cells(Y, 4).Copy
            ActiveSheet.Cells(x, 3).Paste
            Cells(Y, 21).Copy
            ActiveSheet.Cells(x, 4).Paste
            End If
        x = x + 1
        Next Y
    End If
Next wbFile


'concatenate po and promise date
'remove duplicate rows


End Sub
 
Last edited by a moderator:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
This
Code:
Dim WB As Workbook, WS As [COLOR=#ff0000]Worksheets[/COLOR]
should be Worksheet (singular)
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

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