Row search with some merged rows

Luke777

Board Regular
Joined
Aug 10, 2020
Messages
246
Office Version
  1. 365
Platform
  1. Windows
Hi all!

I've got a bit of code that essential scans rows for a value. Looks a little like

VBA Code:
For each cell in Range(cells(searchRow,3),cells(searchRow,lastCol))
If cell.value = ...

Once the value is found and I've done whatever with it, I then +1 to searchRow. Simple enough right?

well, when it comes to actually searching rows for cell values, I've noticed that if any cells are merged with the row/s beneath, the results are wonky.

To keep it simple, if I search from row 1 for the word "Pingu" and A1 contains the word "Pingu" I have no problem.

If I search row 1 for the word "Pingu" and A1 is merged with A2 and contains the word "Pingu" I have no problem.

However, if I search row 2 for "Pingu" and A1 and A2 are merged and contain "Pingu", "Pingu" is not detected because it seems like A2 no longer exists.

Is there a way around this other than unmerging cells?

Thanks all
 

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.
Hi,​
as a reminder only the first cell of a merged cells range contains a value​
so this is why when Excel is badly used as a database software it is recommended to never merge cells.​
As your code follows the slowest way then you can check the first cell of the MergeArea property …​
 
Upvote 0

Forum statistics

Threads
1,215,360
Messages
6,124,492
Members
449,166
Latest member
hokjock

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