I cannot get a .find to work on a table column to return the row with a certain value

rtemen

New Member
Joined
Sep 23, 2013
Messages
36
Greetings.
I have a problem getting the .find to work on a table column.
In the table, is a column labeled 'ID'.
Towards the end of my program is the line:
foundrow = summObj.listcolumns...

I have tried for hours to google for help and have tried many different syntaxes and I cannot get it to work.

Here is my program:

Code:
Private Sub Reload_Click()
    
    'Routine to move data to table from Molding Table
    'Check to not overwrite current records but add new ones.
    
    Dim summObj As ListObject
    Dim moldObj As ListObject
    Dim I, X As Integer
    Dim summObjRows As Integer
    Dim moldObjRows As Integer
    Dim key As String
    Dim foundrow As Integer
    
    ' Get the table reference
    Set summObj = Worksheets("Summary").ListObjects("SummaryTable")
    Set moldObj = Worksheets("MoldingData").ListObjects("MoldingTable")
    summObjRows = summObj.ListRows.Count
    moldObjRows = moldObj.ListRows.Count
    
    'Check if table is empty
    If summObjRows = 0 Then
        'Set up the first row
        summObj.ListRows.Add
        summObj.ListColumns("ID").DataBodyRange(1) = "New"
    End If
    
    X = 1
    For I = 1 To moldObj.ListRows.Count
        key = moldObj.DataBodyRange(I, moldObj.ListColumns("ID").DataBodyRange.Column) & "," & moldObj.DataBodyRange(I, moldObj.ListColumns("6-Way").DataBodyRange.Column)
        If moldObj.DataBodyRange(I, moldObj.ListColumns("Volume").DataBodyRange.Column) <> "" Then
        
            If Not (key = summObj.ListColumns("ID").DataBodyRange(X)) Then
                'Insert row into Summary Table unless this is the first row in a blank table.
                If Not summObj.ListColumns("ID").DataBodyRange(X) = "New" Then
                    summObj.ListRows.Add (X)
                End If
                summObj.ListColumns("ID").DataBodyRange(X) = key
                summObj.ListColumns("Volume").DataBodyRange(X) = moldObj.ListColumns("Volume").DataBodyRange(I)
                summObj.ListColumns("Item Name").DataBodyRange(X) = moldObj.ListColumns("Item Name").DataBodyRange(I)
                summObj.ListColumns("Data1").DataBodyRange(X) = moldObj.ListColumns("Data1").DataBodyRange(I)
                summObj.ListColumns("Data2").DataBodyRange(X) = moldObj.ListColumns("Data2").DataBodyRange(I)
            Else
                summObj.ListColumns("Volume").DataBodyRange(X) = moldObj.ListColumns("Volume").DataBodyRange(I)
                summObj.ListColumns("Data2").DataBodyRange(X) = moldObj.ListColumns("Data2").DataBodyRange(I)
            End If
            X = X + 1
        Else
            'Check it to see if it is in Summary, and if so remove it
            foundrow = summObj.ListColumns("ID").DataBodyRange(X).Find(key).Row
        End If
    Next I
    
End Sub

Any help is appreciated.
Rich
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Some Progress...
In my foundrow = summObj.listcolumns... line, I removed the (X).
Now when the string being searched for is in the column, it returns the row number to foundrow.
If the string is not in the column, it raises the Runtime Error '91' error.

Any thoughts?
Rich
 
Upvote 0

Forum statistics

Threads
1,215,406
Messages
6,124,720
Members
449,184
Latest member
COrmerod

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