VBA -- how to search only within a specific column

Rich Seidner

New Member
Joined
Aug 16, 2016
Messages
21
I search for data (it's my Find Next macro) using the following line which works fine ONLY as long as the cursor is in column B. Otherwise i get an error, Run-time error "13" Type Mismatch.

Code:
    ActiveWorkbook.Worksheets("Contacts").Columns(2).Find(FTW, After:=Range(foundtxt)).Select

How do i change my code to make sure it only looks for stuff in Column B and avoids that error message?

Thanks ...
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I forgot to mention that the variable FTW has the string that's being searched for, and the variable foundtxt has a cell address (like $A$500 kind of thing).
 
Upvote 0
If you want to ALWAYS search in Column(2) then try this... the After option will set the search to always be in column B (2) and look below B1

Code:
ActiveWorkbook.Worksheets("Contacts").Columns(2).Find(FTW, After:=Range("B1")).Select
 
Upvote 0

Forum statistics

Threads
1,214,605
Messages
6,120,473
Members
448,967
Latest member
visheshkotha

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