+ Reply to Thread
Results 1 to 7 of 7

type mismatch run time error 13

Hybrid View

  1. #1
    Registered User
    Join Date
    07-25-2019
    Location
    Huddersfield
    MS-Off Ver
    Excel 2010
    Posts
    23

    type mismatch run time error 13

    Hi, I need help with this error please. One of my ex colleagues has left and he created a spreadsheet built with VB/Marcros. Basically there is 7 groups and it splits them all and creates separate excel spreadsheets when clicking the macro button. I had been using this all year but for some reason it brings up this error and highlighting this code:

     If Sheets("Shop Tables").Cells(a, 5).Value = FltVal And Sheets("Shop Tables").Cells(a, 7).Value > 0 Then
    Full code for marcro is this:

    
    Sub GroupSplitter()
    
    Dim fsht As Boolean
    
    WeekNo = Sheets("Front").Range("WeekNo").Value
    ThisBook = ActiveWorkbook.Name
    FN = Sheets("Front").Range("FNAME").Value
    
    fsht = False
    
    For grpNo = 21 To 31
        Sheets("Front").Select
         If Not (IsEmpty(Sheets("Front").Cells(grpNo, 2).Value)) Then
            ' Filter Value - Group/Regional/BDE
            FltVal = Sheets("Front").Cells(grpNo, 2).Value
            ' ######### Loop this section #########
            For aaa = 3 To 5
                Workbooks(ThisBook).Activate
                If Sheets("Front").Cells(grpNo, aaa).Value = "x" Then
                    Sheets("Front").Range("SortBy").Value = Sheets("Front").Cells(9, aaa).Value
                
                    ' Columns to sort by (% / Parcels)
                    ColSort1 = Sheets("Front").Range("ColSort1").Value
                    ColSort2 = Sheets("Front").Range("ColSort2").Value
                    
                    ' Sort Tables
                    ActiveWorkbook.Worksheets("Shop Tables").AutoFilter.Sort.SortFields.Clear
                        ActiveWorkbook.Worksheets("Shop Tables").AutoFilter.Sort.SortFields.Add Key:= _
                            Range(ColSort1 & "4:" & ColSort1 & "10000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
                            :=xlSortNormal
                        ActiveWorkbook.Worksheets("Shop Tables").AutoFilter.Sort.SortFields.Add Key:= _
                            Range(ColSort2 & "4:" & ColSort2 & "10000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
                            :=xlSortNormal
                        With ActiveWorkbook.Worksheets("Shop Tables").AutoFilter.Sort
                            .Header = xlYes
                            .MatchCase = False
                            .Orientation = xlTopToBottom
                            .SortMethod = xlPinYin
                            .Apply
                        End With
                    
                    
                    ' Create new Sheet and copy Header
                    Dim WS As Worksheet
                    Set WS = Sheets.Add
                    WS.Name = "Data"
                    Sheets("Shop Tables").Select
                    Sheets("Shop Tables").Range(Cells(1, 1), Cells(3, 6)).Copy Destination:=Sheets("Data").Cells(1, 1) ' Account Details
                    Sheets("Shop Tables").Range(Cells(1, 7), Cells(3, 9)).Copy Destination:=Sheets("Data").Cells(1, 7) '
                    Sheets("Shop Tables").Range(Cells(1, 10), Cells(3, 12)).Copy Destination:=Sheets("Data").Cells(1, 10)
                    Sheets("Shop Tables").Range(Cells(1, 13), Cells(3, 15)).Copy Destination:=Sheets("Data").Cells(1, 13)
                    
                    
                    a = 4
                    c = 4
                    sID = Sheets("Shop Tables").Cells(a, 1).Value
                    Do Until IsEmpty(sID)
                        If Sheets("Shop Tables").Cells(a, 5).Value = FltVal And Sheets("Shop Tables").Cells(a, 7).Value > 0 Then
                          Sheets("Shop Tables").Range(Cells(a, 1), Cells(a, 6)).Copy Destination:=Sheets("Data").Cells(c, 1)
                          Sheets("Shop Tables").Range(Cells(a, 7), Cells(a, 9)).Copy Destination:=Sheets("Data").Cells(c, 7)
                          Sheets("Shop Tables").Range(Cells(a, 10), Cells(a, 12)).Copy Destination:=Sheets("Data").Cells(c, 10)
                          Sheets("Shop Tables").Range(Cells(a, 13), Cells(a, 15)).Copy Destination:=Sheets("Data").Cells(c, 13)
                          c = c + 1
                        End If
                    sID = Sheets("Shop Tables").Cells(a, 1).Value
                    a = a + 1
                    Loop
                    Sheets("Data").Select
                        ActiveWindow.DisplayGridlines = False
                        Rows("2:2").RowHeight = 36
                        Rows("3:3").RowHeight = 36
                            Cells.Select
                            Cells.EntireColumn.AutoFit
                            Range("A3").Select
                    
                    Sheets("Data").Select
                    ' Delete cols if Depot-Shop or Shop-Customer
                    If aaa = 4 Then Columns("J:O").Delete
                    If aaa = 5 Then
                    Columns("G:I").Delete
                    Columns("J:L").Delete
                    End If
                    If aaa = 4 Or aaa = 5 Then
                        Rows("1:2").Delete
                    End If
                    
                    
                    If fsht Then
                        Sheets("Data").Move After:=Workbooks(NewBk).Sheets(Workbooks(NewBk).Sheets.Count)
                    Else: Sheets("Data").Move
                    End If
                    
                    ActiveSheet.Name = Workbooks(ThisBook).Sheets("Front").Range("SortBy").Value
                    NewBk = "Week " & WeekNo & " - Compliance Report - " & FltVal & ".xlsx"
                    If fsht = False Then ActiveWorkbook.SaveAs Filename:=FN & NewBk
                    fsht = True
                End If
            Next aaa
            ' ######### END - Loop this section #########
        End If
        
        Workbooks(NewBk).Save
        Workbooks(NewBk).Close
        fsht = False
    Next grpNo
    
    End Sub
    Attached Images Attached Images
    Last edited by Sandy2385; 07-25-2019 at 09:02 AM.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,693

    Re: type mismatch run time error 13

    Hi there,

    Just an untested knee-jerk suggestion:

    
    If (Sheets("Shop Tables").Cells(a, 5).Value = FltVal) And (Sheets("Shop Tables").Cells(a, 7).Value > 0) Then

    Hope this helps,

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    07-25-2019
    Location
    Huddersfield
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: type mismatch run time error 13

    Hi Greg,

    Thanks for reply. It still brings up same error and highlighted the same code. See attached.

    Thanks.
    Attached Images Attached Images

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,644

    Re: type mismatch run time error 13

    When the code stops, you need to check the values of grpNo and fltVal.

    The first so you know where in the loop you are and the second to see what you are filtering on.

    Then you need to check where the value comes from in the worksheet. May be that it has been edited inadvertently.



    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    07-25-2019
    Location
    Huddersfield
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: type mismatch run time error 13

    Hi Thanks for reply.

    I have taken on your advice and you was right, it was something about my data. Each row has a group assigned, however one of the rows was showing as N/A. I deleted this row, and then re-ran. It works fine now, so thanks for your help

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,644

    Re: type mismatch run time error 13

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,693

    Re: type mismatch run time error 13

    Hi again,

    Many thanks for your very prompt feedback and also for the (undeserved ) Reputation increase - much appreciated.

    Glad to see that things are working correctly for you now.

    Best regards,

    Greg M

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Run time Error 13: type mismatch
    By DineshPawar in forum Excel General
    Replies: 1
    Last Post: 01-21-2017, 05:29 AM
  2. Run-Time Error '13' Type Mismatch
    By domgilberto in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-22-2016, 09:32 AM
  3. [SOLVED] Run-time error '13': type mismatch VBA
    By Johnatha in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-04-2016, 10:20 PM
  4. run time error '13' type mismatch
    By bqheng in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-27-2015, 08:11 PM
  5. Run-time error: Type mismatch
    By siamadu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2009, 03:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1