Find Cell Value, Count No. Merged Rows, Select Offset Range

DanGK1

Board Regular
Joined
Jul 7, 2010
Messages
60
I have spent hours trying but cannot get there.

I have a spreadsheet of data which is an export from an external program and the layout off this export has merged cells.

I have found the code to count merged cells and managed to add find to that

VBA Code:
Range("A:A").Find(What:="Magento").MergeArea.Rows.Count

What I am trying to do next is select a range based on that merged row count value - offset 2 columns (which is to column C, I can do that), then select a range which is the offset column, the column next to it and the number of rows (which are not merged) based off the value of the Merge Area Row Count. I tried to go back to basics and print the value of the row count to a cell but I couldn't get that to work either.

I welcome suggestions.

Thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Is this what you're after?

VBA Code:
Dim r As Range

With Range("A:A").Find(What:="Magento")
    Set r = .Offset(, 2).Resize(.MergeArea.Rows.Count, 2)
End With

MsgBox r.Address

(Although my preference would be strip out all the merged cells before doing anything!)
 
Upvote 0
Solution
thanks Stephen.

I replaced the message box with
VBA Code:
Range(r.Address).Select

And got just what I wanted (and yes, perhaps I could unmerge first...)
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,665
Members
449,045
Latest member
Marcus05

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