Run time error 5 : Invalid procedure call or arguement

sky1in5

Active Member
Joined
Dec 24, 2012
Messages
396
Posted at Copy cells in every closed worksheets instead of first worksheet to new workbook - Page 2

Code:
     For N = LBound(FName) To UBound(FName)
                
            sFName = FName(N)
            
            Set SheetNum = FunctionModule.GetSheetsName(sFName)
            
            For i = 1 To SheetNum.Count
                    ' Find the last row with data
                    rnum = LastRow(sh)
        
                    ' Set Column A for item name
                    Set destrangeName = sh.Cells(rnum + 1, "A")
                    ' Set Column B for article number
                    Set destrangeArticle = sh.Cells(rnum + 1, "B")
                    ' Set Column C for start date
                    Set destrangeStart = sh.Cells(rnum + 1, "C")
                    ' Set Column D for end date
                    Set destrangeEnd = sh.Cells(rnum + 1, "D")
                    ' Set Column E for promo price
                    Set destrangePrice = sh.Cells(rnum + 1, "E")
        
                    ' Copy item name from other worksheets and insert into current worksheet
                    GetData sFName, SheetNum(i), ws.Range("A2"), destrangeName, False, False
                    ' Copy article number from other worksheets and insert into current worksheet
                    GetData sFName, SheetNum(i), ws.Range("B2"), destrangeArticle, False, False
                    ' Copy start date from other worksheets and insert into current worksheet
                    GetData sFName, SheetNum(i), ws.Range("C2"), destrangeStart, False, False
                    ' Copy end date from other worksheets and insert into current worksheet
                    GetData sFName, SheetNum(i), ws.Range("D2"), destrangeEnd, False, False
                    ' Copy promo price from other worksheets and insert into current worksheet
                    GetData sFName, SheetNum(i), ws.Range("E2"), destrangePrice, False, False
                    
            Next i
        Next N

Code:
Function GetSheetsName(xFile As String) As Collection 'Codes Found online with modifications made
 'Needs a reference to:
 'Microsoft ActiveX Data Object X.X Library
 'Microsoft ADO Ext. X.X for DLL and Security
 
         Dim objConn As Object
         Dim objCat As Object
         Dim tbl As Object
         Dim sConnString As String
         Dim sSheet As String
         Dim Col As New Collection
        
                If Val(Application.Version) < 12 Then
                    sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                "Data Source=" & xFile & ";" & _
                                "Extended Properties=""Excel 8.0;HDR=No"";"
                Else
                    sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                                "Data Source=" & xFile & ";" & _
                                "Extended Properties=""Excel 12.0;HDR=No"";"
                End If
         
         Set objConn = CreateObject("ADODB.Connection")
         objConn.Open sConnString
         Set objCat = CreateObject("ADOX.Catalog")
         Set tbl = CreateObject("ADOX.Table")
         Set objCat.ActiveConnection = objConn
        
         For Each tbl In objCat.Tables
                sSheet = tbl.Name
                sSheet = Application.Substitute(sSheet, "'", "")
                sSheet = Left(sSheet, InStr(1, sSheet, "$", 1) - 1)
                On Error Resume Next
                Col.Add sSheet, sSheet
                On Error GoTo 0
         Next tbl
         
         Set GetSheetsName = Col
         objConn.Close
         Set objCat = Nothing
         Set objConn = Nothing
 
End Function
Public Sub GetData(SourceFile As Variant, SourceSheet As String, _
                   SourceRange As String, TargetRange As Range, Header As Boolean, UseHeaderRow As Boolean)
' 30-Dec-2007, working in Excel 2000-2007
    Dim rsCon As Object
    Dim rsData As Object
    Dim szConnect As String
    Dim szSQL As String
    Dim lCount As Long
    ' Create the connection string.
    If Header = False Then
        If Val(Application.Version) < 12 Then
            szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                        "Data Source=" & SourceFile & ";" & _
                        "Extended Properties=""Excel 8.0;HDR=No"";"
        Else
            szConnect = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                        "Data Source=" & SourceFile & ";" & _
                        "Extended Properties=""Excel 12.0;HDR=No"";"
        End If
    Else
        If Val(Application.Version) < 12 Then
            szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                        "Data Source=" & SourceFile & ";" & _
                        "Extended Properties=""Excel 8.0;HDR=Yes"";"
        Else
            szConnect = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                        "Data Source=" & SourceFile & ";" & _
                        "Extended Properties=""Excel 12.0;HDR=Yes"";"
        End If
    End If
    If SourceSheet = "" Then
        ' workbook level name
        szSQL = "SELECT * FROM " & SourceRange$ & ";"
    Else
        ' worksheet level name or range
        szSQL = "SELECT * FROM [" & SourceSheet$ & "$" & SourceRange$ & "];"
    End If
    On Error Resume Next
    Set rsCon = CreateObject("ADODB.Connection")
    Set rsData = CreateObject("ADODB.Recordset")
    rsCon.Open szConnect
    rsData.Open szSQL, rsCon, 0, 1, 1
    ' Check to make sure we received data and copy the data
    If Not rsData.EOF Then
        If Header = False Then
            TargetRange.Cells(1, 1).CopyFromRecordset rsData
        Else
            'Add the header cell in each column if the last argument is True
            If UseHeaderRow Then
                For lCount = 0 To rsData.Fields.Count - 1
                    TargetRange.Cells(1, 1 + lCount).Value = _
                    rsData.Fields(lCount).Name
                Next lCount
                TargetRange.Cells(2, 1).CopyFromRecordset rsData
            Else
                TargetRange.Cells(1, 1).CopyFromRecordset rsData
            End If
        End If
    Else
        MsgBox "No records returned from : " & SourceFile, vbCritical
    End If
    ' Clean up our Recordset object.
    rsData.Close
    Set rsData = Nothing
    rsCon.Close
    Set rsCon = Nothing
    Exit Sub
End Sub
Function LastRow(sh As Worksheet)
    On Error Resume Next
    LastRow = sh.Cells.Find(What:="*", _
                            After:=sh.Range("A1"), _
                            Lookat:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False).Row
    On Error GoTo 0
End Function

Function Array_Sort(ArrayList As Variant) As Variant
    Dim aCnt As Integer, bCnt As Integer
    Dim tempStr As String
    For aCnt = LBound(ArrayList) To UBound(ArrayList) - 1
        For bCnt = aCnt + 1 To UBound(ArrayList)
            If ArrayList(aCnt) > ArrayList(bCnt) Then
                tempStr = ArrayList(bCnt)
                ArrayList(bCnt) = ArrayList(aCnt)
                ArrayList(aCnt) = tempStr
            End If
        Next bCnt
    Next aCnt
    Array_Sort = ArrayList
End Function

error :
Code:
sSheet = Left(sSheet, InStr(1, sSheet, "$", 1) - 1)

I provided link for the forum i posted in, i got Run time error 5 : Invalid procedure call or arguement at above code. Need help to solve it, thank you.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I don't think that the table name that you have returned contains a trailing dollar symbol. Perhaps you should 1st check if it is a valid sheet table:

Code:
If sSheet Like "*$" Then
    sSheet = Left(sSheet, InStr(1, sSheet, "$", 1) - 1)
End If

Just remember that if it isn't a valid sheet that you need to omit it from the collection.
 
Upvote 0
hi Jon von der Heyden thanks for your help, i tried to retrieve some of the files, some i am able to retrieve but some got Run time error 5 : Invalid procedure call or arguement. i do not know how that code works. can u describle to me how that code work and what should i replace the $ with?
 
Upvote 0
i tried your code, it works, but out of 3 sheets, it retrieve only 2 sheets. thanks alot for helping me. any other way i can retrieve 3/3 sheets?
 
Upvote 0
Try this:
Code:
Public Function GetSheetsName(xFile As String) As Collection    
    Dim objConn As Object
    Dim objCat As Object
    Dim tbl As Object
    Dim sConnString As String
    Dim sSheet As String
    Dim Col As New Collection
    
           If Val(Application.Version) < 12 Then
               sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                           "Data Source=" & xFile & ";" & _
                           "Extended Properties=""Excel 8.0;HDR=No"";"
           Else
               sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                           "Data Source=" & xFile & ";" & _
                           "Extended Properties=""Excel 12.0;HDR=No"";"
           End If
    
    Set objConn = CreateObject("ADODB.Connection")
    objConn.Open sConnString
    
    Set objCat = CreateObject("ADOX.Catalog")
    Set tbl = CreateObject("ADOX.Table")
    Set objCat.ActiveConnection = objConn
    
    For Each tbl In objCat.Tables
           sSheet = tbl.Name
           If sSheet Like "*$" Then
            sSheet = Left$(sSheet, Len(sSheet) - 1)
           End If
           Col.Add sSheet, sSheet
    Next tbl
    
    Set GetSheetsName = Col
    objConn.Close
    Set objCat = Nothing
    Set objConn = Nothing
End Function

I've tested this and it returns all sheet names for me without fail.
 
Upvote 0
Code:
Public Sub GetData(SourceFile As Variant, SourceSheet As String, _
                   SourceRange As String, TargetRange As Range, Header As Boolean, UseHeaderRow As Boolean)
' 30-Dec-2007, working in Excel 2000-2007
    Dim rsCon As Object
    Dim rsData As Object
    Dim szConnect As String
    Dim szSQL As String
    Dim lCount As Long
    ' Create the connection string.
    If Header = False Then
        If Val(Application.Version) < 12 Then
            szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                        "Data Source=" & SourceFile & ";" & _
                        "Extended Properties=""Excel 8.0;HDR=No"";"
        Else
            szConnect = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                        "Data Source=" & SourceFile & ";" & _
                        "Extended Properties=""Excel 12.0;HDR=No"";"
        End If
    Else
        If Val(Application.Version) < 12 Then
            szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                        "Data Source=" & SourceFile & ";" & _
                        "Extended Properties=""Excel 8.0;HDR=Yes"";"
        Else
            szConnect = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                        "Data Source=" & SourceFile & ";" & _
                        "Extended Properties=""Excel 12.0;HDR=Yes"";"
        End If
    End If
    If SourceSheet = "" Then
        ' workbook level name
        szSQL = "SELECT * FROM " & SourceRange$ & ";"
    Else
        ' worksheet level name or range
        szSQL = "SELECT * FROM [" & SourceSheet$ & "$" & SourceRange$ & "];"
    End If
    On Error Resume Next
    Set rsCon = CreateObject("ADODB.Connection")
    Set rsData = CreateObject("ADODB.Recordset")
    rsCon.Open szConnect
    rsData.Open szSQL, rsCon, 0, 1, 1
    ' Check to make sure we received data and copy the data
    If Not rsData.EOF Then
        If Header = False Then
            TargetRange.Cells(1, 1).CopyFromRecordset rsData
        Else
            'Add the header cell in each column if the last argument is True
            If UseHeaderRow Then
                For lCount = 0 To rsData.Fields.Count - 1
                    TargetRange.Cells(1, 1 + lCount).Value = _
                    rsData.Fields(lCount).Name
                Next lCount
                TargetRange.Cells(2, 1).CopyFromRecordset rsData
            Else
                TargetRange.Cells(1, 1).CopyFromRecordset rsData
            End If
        End If
    Else
        MsgBox "No records returned from : " & SourceFile, vbCritical
    End If
    ' Clean up our Recordset object.
    rsData.Close
    Set rsData = Nothing
    rsCon.Close
    Set rsCon = Nothing
    Exit Sub
End Sub
Function LastRow(sh As Worksheet)
    On Error Resume Next
    LastRow = sh.Cells.Find(What:="*", _
                            After:=sh.Range("A1"), _
                            Lookat:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False).Row
    On Error GoTo 0
End Function

Function Array_Sort(ArrayList As Variant) As Variant
    Dim aCnt As Integer, bCnt As Integer
    Dim tempStr As String
    For aCnt = LBound(ArrayList) To UBound(ArrayList) - 1
        For bCnt = aCnt + 1 To UBound(ArrayList)
            If ArrayList(aCnt) > ArrayList(bCnt) Then
                tempStr = ArrayList(bCnt)
                ArrayList(bCnt) = ArrayList(aCnt)
                ArrayList(aCnt) = tempStr
            End If
        Next bCnt
    Next aCnt
    Array_Sort = ArrayList
End Function

Code:
Sub GetFiles()
    Dim SaveDriveDir As String, MyPath As String
    Dim FName As Variant, N As Long
    Dim rnum As Long, destrangeArticle As Range
    Dim destrangeStart As Range, destrangeEnd As Range
    Dim destrangePrice As Range, destrangeName As Range
    Dim sh As Worksheet, ws As Worksheet
    Dim SheetNum As Collection, sFName As String
    
    'Set a dialog for opening folder and multiply files
    MyPath = Application.DefaultFilePath
    FName = Application.GetOpenFilename(filefilter:="Excel Files,*.xl*", _
                                        MultiSelect:=True)
    If IsArray(FName) Then
        ' Sort the Array
        FName = Array_Sort(FName)
        Application.ScreenUpdating = False
        
        Set sh = Worksheets("Promotion")
        Set ws = Worksheets("Config")
        
        ' Loop through all files selected in the dialog
        For N = LBound(FName) To UBound(FName)
                              
            sFName = FName(N)
            
            Set SheetNum = FunctionModule.GetSheetsName(sFName)
            
            For i = 1 To SheetNum.Count
                    ' Find the last row with data
                    rnum = LastRow(sh)
        
                    ' Set Column A for item name
                    Set destrangeName = sh.Cells(rnum + 1, "A")
                    ' Set Column B for article number
                    Set destrangeArticle = sh.Cells(rnum + 1, "B")
                    ' Set Column C for start date
                    Set destrangeStart = sh.Cells(rnum + 1, "C")
                    ' Set Column D for end date
                    Set destrangeEnd = sh.Cells(rnum + 1, "D")
                    ' Set Column E for promo price
                    Set destrangePrice = sh.Cells(rnum + 1, "E")
        
                    ' Copy item name from other worksheets and insert into current worksheet
                    GetData FName(N), SheetNum(i), ws.Range("A2"), destrangeName, False, False
                    ' Copy article number from other worksheets and insert into current worksheet
                    GetData FName(N), SheetNum(i), ws.Range("B2"), destrangeArticle, False, False
                    ' Copy start date from other worksheets and insert into current worksheet
                    GetData FName(N), SheetNum(i), ws.Range("C2"), destrangeStart, False, False
                    ' Copy end date from other worksheets and insert into current worksheet
                    GetData FName(N), SheetNum(i), ws.Range("D2"), destrangeEnd, False, False
                    ' Copy promo price from other worksheets and insert into current worksheet
                    GetData FName(N), SheetNum(i), ws.Range("E2"), destrangePrice, False, False
                    
            Next i
        Next N
    End If
    
    Application.ScreenUpdating = True
    
    ' Set money format for promo price
    Range("E2:E1000").NumberFormat = "$#,##0.00"
    ' Set day/month/year format for start and end date
    Range("C2:D1000").NumberFormat = "dd/mm/yy"
    ' Set text format for article number
    Range("B2:B1000").NumberFormat = "@"
End Sub

is there something wrong with my getdata code? i set on error resume next because i keep get error at this part
Code:
 If SourceSheet = "" Then
        ' workbook level name
        szSQL = "SELECT * FROM " & SourceRange$ & ";"
    Else
        ' worksheet level name or range
        szSQL = "SELECT * FROM [" & SourceSheet$ & "$" & SourceRange$ & "];"
    End If
    On Error Resume Next
this is where i keep get error on. i use resume next to get the result i want, the result did appear on my sheet. Due to some error, i cannot retrieve all worksheets, but retrieve majority of it.
 
Upvote 0
Thanks for helping me, it a huge coding i done with my colleague but still unable to get it right.

i am using ado is because i do not want the files to pop out 1 by 1.
i got 600+ excel files to retrieve data in and inside 600+ excel files there are some with 2 to 4 worksheets in it.
function i use getsheetname and getdata array sorting and lastrow.
 
Last edited:
Upvote 0
hi Jon von der Heyden there are no error description. i set it on error resume next to skip the error. can you help me to run though my code to catch the error?

Function Module
Code:
Option Explicit
Public Function GetSheetsName(xFile As String) As Collection
    Dim objConn As Object
    Dim objCat As Object
    Dim tbl As Object
    Dim sConnString As String
    Dim sSheet As String
    Dim Col As New Collection
    
           If Val(Application.Version) < 12 Then
               sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                           "Data Source=" & xFile & ";" & _
                           "Extended Properties=""Excel 8.0;HDR=No"";"
           Else
               sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                           "Data Source=" & xFile & ";" & _
                           "Extended Properties=""Excel 12.0;HDR=No"";"
           End If
    
    Set objConn = CreateObject("ADODB.Connection")
    objConn.Open sConnString
    
    Set objCat = CreateObject("ADOX.Catalog")
    Set tbl = CreateObject("ADOX.Table")
    Set objCat.ActiveConnection = objConn
    
    For Each tbl In objCat.Tables
           sSheet = tbl.Name
           If sSheet Like "*$" Then
            sSheet = Left$(sSheet, Len(sSheet) - 1)
           End If
           Col.Add sSheet, sSheet
    Next tbl
    
    Set GetSheetsName = Col
    objConn.Close
    Set objCat = Nothing
    Set objConn = Nothing
    
End Function
Public Sub GetData(SourceFile As Variant, SourceSheet As String, _
                   SourceRange As String, TargetRange As Range, Header As Boolean, UseHeaderRow As Boolean)
' 30-Dec-2007, working in Excel 2000-2007
    Dim rsCon As Object
    Dim rsData As Object
    Dim szConnect As String
    Dim szSQL As String
    Dim lCount As Long
    ' Create the connection string.
    If Header = False Then
        If Val(Application.Version) < 12 Then
            szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                        "Data Source=" & SourceFile & ";" & _
                        "Extended Properties=""Excel 8.0;HDR=No"";"
        Else
            szConnect = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                        "Data Source=" & SourceFile & ";" & _
                        "Extended Properties=""Excel 12.0;HDR=No"";"
        End If
    Else
        If Val(Application.Version) < 12 Then
            szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                        "Data Source=" & SourceFile & ";" & _
                        "Extended Properties=""Excel 8.0;HDR=Yes"";"
        Else
            szConnect = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                        "Data Source=" & SourceFile & ";" & _
                        "Extended Properties=""Excel 12.0;HDR=Yes"";"
        End If
    End If
    If SourceSheet = "" Then
        ' workbook level name
        szSQL = "SELECT * FROM " & SourceRange$ & ";"
    Else
        ' worksheet level name or range
        szSQL = "SELECT * FROM [" & SourceSheet$ & "$" & SourceRange$ & "];"
    End If
    On Error Resume Next
    Set rsCon = CreateObject("ADODB.Connection")
    Set rsData = CreateObject("ADODB.Recordset")
    rsCon.Open szConnect
    rsData.Open szSQL, rsCon, 0, 1, 1
    ' Check to make sure we received data and copy the data
    If Not rsData.EOF Then
        If Header = False Then
            TargetRange.Cells(1, 1).CopyFromRecordset rsData
        Else
            'Add the header cell in each column if the last argument is True
            If UseHeaderRow Then
                For lCount = 0 To rsData.Fields.Count - 1
                    TargetRange.Cells(1, 1 + lCount).Value = _
                    rsData.Fields(lCount).Name
                Next lCount
                TargetRange.Cells(2, 1).CopyFromRecordset rsData
            Else
                TargetRange.Cells(1, 1).CopyFromRecordset rsData
            End If
        End If
    Else
        MsgBox "No records returned from : " & SourceFile, vbCritical
    End If
    ' Clean up our Recordset object.
    rsData.Close
    Set rsData = Nothing
    rsCon.Close
    Set rsCon = Nothing
    Exit Sub
End Sub
Function LastRow(sh As Worksheet)
    On Error Resume Next
    LastRow = sh.Cells.Find(What:="*", _
                            After:=sh.Range("A1"), _
                            Lookat:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False).Row
    On Error GoTo 0
    
End Function

Function Array_Sort(ArrayList As Variant) As Variant
    Dim aCnt As Integer, bCnt As Integer
    Dim tempStr As String
    For aCnt = LBound(ArrayList) To UBound(ArrayList) - 1
        For bCnt = aCnt + 1 To UBound(ArrayList)
            If ArrayList(aCnt) > ArrayList(bCnt) Then
                tempStr = ArrayList(bCnt)
                ArrayList(bCnt) = ArrayList(aCnt)
                ArrayList(aCnt) = tempStr
            End If
        Next bCnt
    Next aCnt
    Array_Sort = ArrayList
    
End Function

Normal Module
Code:
Sub GetFiles()
    Dim SaveDriveDir As String, MyPath As String
    Dim FName As Variant, N As Long
    Dim rnum As Long, destrangeArticle As Range
    Dim destrangeStart As Range, destrangeEnd As Range
    Dim destrangePrice As Range, destrangeName As Range
    Dim sh As Worksheet, ws As Worksheet
    Dim SheetNum As Collection, sFName As String
    
    'Set a dialog for opening folder and multiply files
    MyPath = Application.DefaultFilePath
    FName = Application.GetOpenFilename(filefilter:="Excel Files,*.xl*", _
                                        MultiSelect:=True)
    If IsArray(FName) Then
        ' Sort the Array
        FName = Array_Sort(FName)
        Application.ScreenUpdating = False
        
        Set sh = Worksheets("Promotion")
        Set ws = Worksheets("Config")
        
        ' Loop through all files selected in the dialog
        For N = LBound(FName) To UBound(FName)
                              
            sFName = FName(N)
            
            Set SheetNum = FunctionModule.GetSheetsName(sFName)
            
            For i = 1 To SheetNum.Count
                    ' Find the last row with data
                    rnum = LastRow(sh)
        
                    ' Set Column A for item name
                    Set destrangeName = sh.Cells(rnum + 1, "A")
                    ' Set Column B for article number
                    Set destrangeArticle = sh.Cells(rnum + 1, "B")
                    ' Set Column C for start date
                    Set destrangeStart = sh.Cells(rnum + 1, "C")
                    ' Set Column D for end date
                    Set destrangeEnd = sh.Cells(rnum + 1, "D")
                    ' Set Column E for promo price
                    Set destrangePrice = sh.Cells(rnum + 1, "E")
        
                    ' Copy item name from other worksheets and insert into current worksheet
                    GetData FName(N), SheetNum(i), ws.Range("A2"), destrangeName, False, False
                    ' Copy article number from other worksheets and insert into current worksheet
                    GetData FName(N), SheetNum(i), ws.Range("B2"), destrangeArticle, False, False
                    ' Copy start date from other worksheets and insert into current worksheet
                    GetData FName(N), SheetNum(i), ws.Range("C2"), destrangeStart, False, False
                    ' Copy end date from other worksheets and insert into current worksheet
                    GetData FName(N), SheetNum(i), ws.Range("D2"), destrangeEnd, False, False
                    ' Copy promo price from other worksheets and insert into current worksheet
                    GetData FName(N), SheetNum(i), ws.Range("E2"), destrangePrice, False, False
                    
            Next i
        Next N
    End If
    
    Application.ScreenUpdating = True
    
    ' Set money format for promo price
    Range("E2:E1000").NumberFormat = "$#,##0.00"
    ' Set day/month/year format for start and end date
    Range("C2:D1000").NumberFormat = "dd/mm/yy"
    ' Set text format for article number
    Range("B2:B1000").NumberFormat = "@"
    
End Sub

the code is working "properly" because i set on error resume next to skip all the error but instead of retrieving all the sheets, it only retrieve majority of the sheets.
thanks and appreciated.
 
Last edited:
Upvote 0
Please remove the On Error Resume Next and then report back on the error description and check again what line it breaks on please.
 
Upvote 0

Forum statistics

Threads
1,216,430
Messages
6,130,573
Members
449,585
Latest member
c_clark

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