+ Reply to Thread
Results 1 to 3 of 3

Excel 2013 ListView Run-Time error '13', type mismatch

Hybrid View

  1. #1
    Registered User
    Join Date
    03-18-2014
    Location
    Mississauga
    MS-Off Ver
    Excel 2013
    Posts
    5

    Excel 2013 ListView Run-Time error '13', type mismatch

    I've added this code to my worksheet as a test, it worked fine on the sample workbook, but when I run the same code in my production workbook I get an error. The userform and listview were duplicated in the prod workbook. I did notice that when I try to manually add a Listview control v6.0 to the userform, I get a blank. When I try clicking on where the listview should be in the userform I get a Library not registered error. I have scrubbed most of the VBA code and userforms from the attached file "LISTVIEW NOT WORKING.xlsm" so you can compare the 2 spreadsheets (they should be the same, but one works and the other does not).

    Private Sub LoadListView()
    
        'Declare the variables
        Dim wksSource As Worksheet
        Dim rngData As Range
        Dim rngCell As Range
        Dim LstItem As ListItem
        Dim RowCount As Long
        Dim ColCount As Long
        Dim i As Long
        Dim j As Long
        
        'Set the source worksheet
        Set wksSource = Worksheets("THistory")
        
        'Set the source range
        Set rngData = wksSource.Range("A1").CurrentRegion
        
        'Add the column headers
        For Each rngCell In rngData.Rows(1).Cells
            Form3.ListView1.ColumnHeaders.Add Text:=rngCell.Value, Width:=90
        Next rngCell
        
        'Count the number of rows in the source range
        RowCount = rngData.Rows.Count
        
        'Count the number of columns in the source range
        ColCount = rngData.Columns.Count
        
        'Fill the ListView
        For i = 2 To RowCount
            Set LstItem = Form3.ListView1.ListItems.Add(Text:=rngData(i, 1).Value) ' THIS IS WHERE I GET THE ERROR!!!
            'LstItem.ForeColor = vbBlue
            For j = 2 To ColCount
                'LstItem.ForeColor = vbRed
                LstItem.ListSubItems.Add Text:=rngData(i, j).Value
            Next j
        Next i
        
    End Sub
    Attached Files Attached Files
    Last edited by PerryBeatty; 03-19-2014 at 07:12 AM. Reason: Marked the CODE

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Excel 2013 ListView Run-Time error '13', type mismatch

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

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

    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



    Also please attach a sample production workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    03-18-2014
    Location
    Mississauga
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: Excel 2013 ListView Run-Time error '13', type mismatch

    I've included the data the ListView is accessing, can anyone assist in directing me as to why I'm getting the "type mismatch" error (code highlighted in red)?

    Name Row# Description Qty Unit Price Date Total
    ACCESSORIES 2 Glass 24 EA 12 41710 288
    ACCESSORIES 4 Metal 5 EA 1000 41710 5000
    ACCESSORIES 6 Pulls 56 EA 300 41710 16800
    BACK WALL 13 Filler 15 EA 23 41710 345
    BACK WALL 15 Lens 18 EA 490 41710 8820
    BACK WALL 17 Mini 13 EA 215 41710 2795
    BACK WALL 18 Make Up 8 EA 1115 41704 8920
    BLACK TABLES 28 Service 5 EA 575 41710 2875
    TEMPORARY 44 Crate 5 EA 775 41704 3875

    Private Sub LoadListView()
        Dim wksSource As Worksheet
        Dim rngData As Range
        Dim rngCell As Range
        Dim LstItem As ListItem
        Dim RowCount As Long
        Dim ColCount As Long
        Dim i As Long
        Dim j As Long
        Set wksSource = Worksheets("Sheet1")
        Set rngData = wksSource.Range("A1").CurrentRegion
        For Each rngCell In rngData.Rows(1).Cells
            Form3.ListView1.ColumnHeaders.Add Text:=rngCell.Value, Width:=90
        Next rngCell
        RowCount = rngData.Rows.Count
        ColCount = rngData.Columns.Count
        For i = 2 To RowCount
            Set LstItem = Form3.ListView1.ListItems.Add(Text:=rngData(i, 1).Value)
            LstItem.ForeColor = vbBlue
            For j = 2 To ColCount
                LstItem.ListSubItems.Add Text:=rngData(i, j).Value
            Next j
        Next i
        
    End Sub

+ 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. Excel VBA Run-time error '13' Type mismatch
    By pankajpm in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-27-2013, 05:34 AM
  2. [SOLVED] Excel VBA Run-time error '13' Type mismatch
    By mackypogi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2013, 02:15 AM
  3. Excel VBA Run-time error '13' Type mismatch
    By edgaryp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2013, 06:48 PM
  4. Type mismatch Error observer in Excel 2013
    By mechbhaskar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2013, 07:50 AM
  5. [SOLVED] Excel VBA Frustrating Run-time error '13' Type mismatch
    By shastamccloud in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-08-2010, 02:34 AM

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