How to search for words in a range or range of cells and highlight them in Excel - Excel VBA Macro

Is that the use of Microsoft Office Exel is somewhat underestimated due to the apparent complexity of using some functions. As well as the way to implement its formulas to perform the calculation, but nothing is further from reality. It's just a matter of knowing what you should do for each case and get the most out of it  tool.

That's why we want to show you how Exel can find a value or word in a certain range. To do this we program a Macro that does this search for us, we learn how to search for words in a range or range of cells and highlight them in Excel, Excel VBA Macro.




How to find words in a range or range of cells and highlight them in Excel

We will schedule one Macro which allows us to search for a word in a certain range and this in turn highlights the cell where the word is found with a predetermined color. Basically, this is what we are going to do and we tell you in advance that it is a very simple operation to do.

How to search for words in a range or range of cells and highlight them in Excel - Excel VBA Macro

The first thing you should do to learn how to program this step by step Macro function is first in your spreadsheet, you can create a very simple table. In it you will insert only two columns, one of which you will insert Name and the other column the Surname. Once you have the table ready, we will move on to the next step.

The next step is to insert a button that will be called Search word, for this we will go to the Insert tab. And after creating a clip, we will select Shapes, you can find the one you want, oval, rectangular, etc. Once you find it, you select it and place it anywhere in the spreadsheet next to the table.




After placing it, you will create a correct clip so that the options appear and select Edit text. And here you add the name of your button, which can be to search for a word, put it in the size you want and then to finish press Enter. We will now move on to programming the Macro, but first we will save it.

Using VBA to Program Macros

To do this we will go to the File tab, then Save as and finally we choose a path. We make a clip in Browse, you look for where to save it and in type you have to make a clip. When you do that, you should look for the macro-enabled Exel Book option.

You select and then change the name to the one you want and finally create a clip in Save. Let's go back to our spreadsheet to create the Macro, for this we will do it through the codes of the Visual Basic applications.

For this we will do the key combinations first the Alt key and then F11 and a window will appear on your spreadsheet. With it we will create the Macro. But first we will create a module, for that we go to File is the Create option, create a clip and then to Module, and we will write the following instructions in General.

Sub Search word () and then hit Enter, when you do, the word End Sub will appear under your instructions. But basically it should look like this:


Secondary Word Search ()


    Cell dim as range


    Word dim as a string

Word = ImputBox ("Enter the word to search for:")

                 For each cell in selection

                       If Cell.Value as Word then


                            Cell. Inside. Color Index = 36


                       End if


                 Next cell

End subtitle

How to search for words in a range or range of cells and highlight them in Excel - Excel VBA Macro

Then, to finish, click on the option of rescue, now go to your spreadsheet and select the column where you want to search for the word. Then make a clip on the Search word button and put the word you want to search for and then make a clip on OKAY. The cell or cells highlighted in a color with the name you are looking for will instantly appear.

add a comment of How to search for words in a range or range of cells and highlight them in Excel - Excel VBA Macro
Comment sent successfully! We will review it in the next few hours.