Find a text in a merged cell and select it

nikolaikolev

New Member
Joined
Nov 22, 2011
Messages
24
Hi guys,
i am struggling to make a macro that will find the word "Yes" in column A and select it.
The word "Yes" is in column A but on that row where the word is, all cells from column A to column H are merged (as in the attached file).
Any ideas how can i possibly do that ?

Untitled.jpg
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Merged cells are a huge pain in the neck that cause all sort of problems with things like sorting and VBA.
It is highly advised that you remove them.

You can achieve the exact same visual effect without all the issues by using the "Center Across Selection" formatting option instead.
See: Tom’s Tutorials For Excel: Using Center Across Selection Instead of Merging Cells – Tom Urtis

If you do this, then you should have no issues making the VBA code that you want.
You can use the Macro Recorder to get most of the code that you need.
 
Upvote 0
I agree with Joe about avoiding using merged cells; however, to answer you question, this should work...
VBA Code:
Columns("A:H").Find("yes", Cells(Rows.Count, "A"), xlValues, xlWhole, , xlNext, False).Select
Note I had to specify all the columns in your merge to make it work.
 
Upvote 0
I agree with Joe about avoiding using merged cells; however, to answer you question, this should work...
VBA Code:
Columns("A:H").Find("yes", Cells(Rows.Count, "A"), xlValues, xlWhole, , xlNext, False).Select
Note I had to specify all the columns in your merge to make it work.
Thanks mate the code work just fine but the problem is that it finds the first occurance for the word Yes that is located in E45, but the word Yes i am looking for is in A143
 
Upvote 0
Thanks mate the code work just fine but the problem is that it finds the first occurance for the word Yes that is located in E45, but the word Yes i am looking for is in A143
Is there any way to make it search for the word from lets say row 80 downwards ?
 
Upvote 0
Thanks mate the code work just fine but the problem is that it finds the first occurance for the word Yes that is located in E45, but the word Yes i am looking for is in A143
That is precisely one of problems with using merged cells! If you have merged columns A:H, you cannot tell it to only look at column A and not column H, as they are all merged!
That is why the other option I suggested would work better.

Is there any way to make it search for the word from lets say row 80 downwards ?
You can search any range that you define. It does not have to be a full column.
You can search column A, started in row 80, down to the last row with data in column A.
You can define that range like this:
VBA Code:
Dim lr as Long
Dim rng as Range

'Find last row with data in column A
lr = Cells(Rows.Count, "A").End(xlUp).Row

'Define range
Set rng = Range("A80:A" & lr)
Note that you still may have issues if you do not rectify the merged cells issues mentioned above.
 
Upvote 0
That is precisely one of problems with using merged cells! If you have merged columns A:H, you cannot tell it to only look at column A and not column H, as they are all merged!
That is why the other option I suggested would work better.


You can search any range that you define. It does not have to be a full column.
You can search column A, started in row 80, down to the last row with data in column A.
You can define that range like this:
VBA Code:
Dim lr as Long
Dim rng as Range

'Find last row with data in column A
lr = Cells(Rows.Count, "A").End(xlUp).Row

'Define range
Set rng = Range("A80:A" & lr)
Note that you still may have issues if you do not rectify the merged cells issues mentioned above.
thanks pal
 
Upvote 0
You are welcome.
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,767
Members
449,049
Latest member
greyangel23

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