Find solicits Object Required

bkelly

Active Member
Joined
Jan 28, 2005
Messages
465
I recorded a macro and used the generated code, changing it to save the results so I can discover the row where found. But the error message does not suggest what object is needed or where it is needed. What do I need to change?

VBA Code:
Sub pull_titles_back_to_their_column()
  Dim col_num As Integer
  Dim test_col As Variant 
  Dim found_row As Long
  Dim found_cell As Variant  ' Tried Range, same result

  For col_num = COL_LAST_NAME To COL_SUFFIX

     test_col = Columns(COL_LAST_NAME)
     found_cell = test_col.Find( _ ‘ These 9 lines are highlighted
      What:="mr", _
      After:=ActiveCell, _
      LookIn:=xlFormulas, _
      LookAt:=xlWhole, _
      SearchOrder:=xlByColumns, _
      SearchDirection:=xlNext, _
      MatchCase:=False, _
      SearchFormat:=False).Activate

found_row = found_cell.Rows
Next col_num
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Sorry about that. They are constants declared at the very top. Here are a few of them.
Public Const COL_LAST_NAME As Integer = 6
Public Const COL_FIRST_NAME As Integer = 7
Public Const COL_MIDDLE_NAMES As Integer = 8
Public Const COL_SUFFIX As Integer = 9
 
Upvote 0
Try (Untested)...

VBA Code:
Sub pull_titles_back_to_their_column()
    Dim col_num As Integer
    Dim test_col As Long
    Dim found_row As Long
    Dim found_cell As Range                      ' Tried Range, same result

    For col_num = COL_LAST_NAME To COL_SUFFIX

        test_col = Columns(COL_LAST_NAME)
        Set found_cell = test_col.Find( _
                         What:="mr", _
                         After:=test_col.Cells(1, 1), _
                         LookIn:=xlFormulas, _
                         LookAt:=xlWhole, _
                         SearchOrder:=xlByColumns, _
                         SearchDirection:=xlNext, _
                         MatchCase:=False, _
                         SearchFormat:=False)

        found_row = found_cell.Row
    Next col_num
End Sub
 
Upvote 0
That changed the problem to syntax error, a more basic error. Also tried this
After:=.cells( col_num, 1), _
with a no go.
Option Expllicit is set so its pretty sure not a syntax error or miss-named variable.
 
Upvote 0

Forum statistics

Threads
1,214,545
Messages
6,120,132
Members
448,947
Latest member
test111

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