Check if in column A some words are present

assurdo

New Member
Joined
Sep 22, 2014
Messages
13
Hi,
how do I check, with a macro, if a .txt file that I have imported in Excel, contains some word? If it contains them, I need to show a error message, if it does not contain it, it's fine.
When the file txt is imported in Excel, it is in the worksheet "Import". So I can check in the column A of "Import" is the words are found. Thank you.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I don't know of the amount of the data you need to import.
I came up with a formula. First some info.

I created two sheets:
- Import - this one contains imported data (obviously ;) )
- Verification - this one contains keywords to search for and a searching formula


Excel 2016 (Windows) 32 bit
A
1Imported data
2Imp1
3Imp2
4car
5forest
6something
7smthelse
8anything
9home
10sky

<tbody>
</tbody>
Import sheet above
Excel 2016 (Windows) 32 bit
ABC
1keyword to look forKeywords found?Amount of keywords found
2carKeywords found!2
3forest

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Verification sheet

Array Formulas
CellFormula
B2{=IF(SUM(IF(ISERROR(MATCH(A2:A4,Import!$A$2:$A$13,0)),0,1))>0,"Keywords found!","")}
C2{=SUM(IF(ISERROR(MATCH(A2:A4,Import!$A$2:$A$13,0)),0,1))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>

What do you think?
 
Upvote 0
I don't know of the amount of the data you need to import.
I came up with a formula. First some info.

I created two sheets:
- Import - this one contains imported data (obviously ;) )
- Verification - this one contains keywords to search for and a searching formula


Excel 2016 (Windows) 32 bit
A
1Imported data
2Imp1
3Imp2
4car
5forest
6something
7smthelse
8anything
9home
10sky

<tbody>
</tbody>
Import sheet above
Excel 2016 (Windows) 32 bit
ABC
1keyword to look forKeywords found?Amount of keywords found
2carKeywords found!2
3forest

<tbody>
</tbody>
Verification sheet

Array Formulas
CellFormula
B2{=IF(SUM(IF(ISERROR(MATCH(A2:A4,Import!$A$2:$A$13,0)),0,1))>0,"Keywords found!","")}
C2{=SUM(IF(ISERROR(MATCH(A2:A4,Import!$A$2:$A$13,0)),0,1))}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>

What do you think?


It's fine, thank you!
Another solution can be:

1) Formula in cell B10 for example: =CONTA.SE(Import!A:A; "Word to search")
+
2) Macro: If Range("B10") > 0 Then MsgBox "....."
 
Upvote 0
Ooooh. You want to look for one word only?

That does change things a bit.

Your macro is almost ready. Do you still need assistance with it? :)

One more thing. My previous formula can be wrote differently:

Excel 2016 (Windows) 32 bit
B
3Keywords found!

<colgroup><col style="width: 25pxpx"><col></colgroup><thead>
</thead><tbody>
</tbody>
Verification

Array Formulas
CellFormula
B3{=IF(SUM(IF(COUNTIF(Import!$A$2:$A$13,Verification!A2:A4)>0,1,0))>0,"Keywords found!","")}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,841
Members
449,193
Latest member
MikeVol

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