loop through merged cells in a Column to get their addresses

Sagar0650

Board Regular
Joined
Nov 25, 2019
Messages
55
Office Version
  1. 2019
Platform
  1. Windows
I have one column. say column A, which has multiple merged cells of different ranges.
for example first cell is merged from A2 to A15 whereas second merged cell ranges from A16 to A115
now i want to run through entire column to get the address of each merged cell.
i have code which helps me to get the address of the only first merge cell.
can anyone help me to run a loop to get these cell address?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
i'll share the exact information with you in coming couple of days.
When you do that you should also clarify this part
  • Next step is to find the largest number present from that range.
  • Last step is to find the corresponding value from “col5” of that large number. Use of msgbox to display the result.
What should the last step be if 2 or 3 or 10 cells in the last column are all the equal largest in that range?
 
Upvote 0
Hi @Sagar0650, I apologize if any of my comments bothered you, my intention is only to help you.

The macro of post #26 works with the sample data. But I don't think you want the final result only in a msgbox.
I go further, if you need any statistics or submit a report with those results, I suppose it would be best to store them in a cell.

Hence my next proposal: if you remove the combined cells (because for a presentation they look beautiful, but for the handling of data they become complicated, even as you saw the code in VBA it becomes complex), however, if you fill in the cells You can use a pivot table.

With the pivot table, you can find the maximum values, sums, counts, etc. Check out the example below:


1575039741721.png


Either way, let me know if you need any changes in the macro and I will gladly support you.
 
Upvote 0
I apologize if any of my comments bothered you, my intention is only to help you.
please you don't apologize to me
i know you have tried to help me.
to be very honest with you, i am currently outside of my business working hours.
i will surely goinf to contact you guys with proper input when i am back to work.
But, could you do the test with the code of post #26?
yes i did check, but as you said correctly it is the formatting of existing cells which is why the code is not working with me.
Hence my next proposal: if you remove the combined cells (because for a presentation they look beautiful, but for the handling of data they become complicated, even as you saw the code in VBA it becomes complex), however, if you fill in the cells You can use a pivot table.
i believe this option is without using macro but doing manual task with pivot table right?
output here looks much more easy to handle in further processing.
can you please elaborate more on this?
sorry for bothering you again and again.
Thank you for continuous support.
 
Upvote 0
It is no trouble for me, I like to help you.
Enjoy your weekend, when you return to work, we talk about pivot tables, it is very simple to use, you only select your information, in the menu you select Insert / pivot table. And ready you have your pivot table. Now you just have to accommodate the rows and columns, but with watching a couple of videos on YouTube you will be an expert.
 
Upvote 0
without using macro
If you are interested in doing this without a macro, then you can do it with formulas without un-merging and including if there are multiple maximum values in a 'merged range'.

Either this where ..
L2 & M2 are copied down and
N2 is copied across and down

Book1
ABCDEFGHIJKLMNOPQR
1COL1COL2COL3COL4COL5COL6COL7COL8COL9
2Data 1output11Data 17output7    
3output22Data 250output13output16output17  
4output33Data 3100output21output23   
5output44       
6output55       
7output66
8output77
9Data 2output821
10output917
11output1019
12output1121
13output1223
14output1350
15output1427
16output1529
17output1650
18output1750
19output1835
20output1937
21Data 3output2039
22output21100
23output2243
24output23100
25output2447
26
Sheet3
Cell Formulas
RangeFormula
L2:L6L2=IFERROR(INDEX($A$2:$A$100,MATCH(0,INDEX(COUNTIF($L$1:L1,$A$2:$A$100)+(A$2:A$100=""),0),0)),"")
M2:M6M2=IF(L2="","",MAX(INDEX(I$2:I$100,MATCH(L2,A$2:A$100,0)):INDEX(I$2:I$100,IF(L3="",ROWS(I$2:I$100),MATCH(L3,A$2:A$100,0)-1))))
N2:R6N2=IF(L2="","",IFERROR(INDEX($E:$E,AGGREGATE(15,6,ROW(INDEX($E$2:$E$100,MATCH($L2,$A$2:$A$100,0)):INDEX($E$2:$E$100,IF($L3="",ROWS($E$2:$E$100),MATCH($L3,$A$2:$A$100,0))))/(INDEX($I$2:$I$100,MATCH($L2,$A$2:$A$100,0)):INDEX($I$2:$I$100,IF($L3="",ROWS($I$2:$I$100),MATCH($L3,$A$2:$A$100,0)))=$M2),COLUMNS($N2:N2))),""))



.. or if you want to keep the formulas shorter, we could use a couple of helper columns that use your original idea of capturing the first and last rows of each merged area. The helper columns could be hidden after you populate the formulas in them.
Here .. K2, L2, M2 and N2 are copied down, and
O2 is copied across and down


Book1
ABCDEFGHIJKLMNOPQR
1COL1COL2COL3COL4COL5COL6COL7COL8COL9
2Data 1output1117Data 17output7   
3output22819Data 250output13output16output17 
4output332099Data 3100output21output23  
5output44        
6output55        
7output66
8output77
9Data 2output821
10output917
11output1019
12output1121
13output1223
14output1350
15output1427
16output1529
17output1650
18output1750
19output1835
20output1937
21Data 3output2039
22output21100
23output2243
24output23100
25output2447
26
Sheet4
Cell Formulas
RangeFormula
K2:K6K2=IFERROR(AGGREGATE(15,6,ROW(A:A)/(A$2:A$100<>""),ROWS(K$2:K2)),"")
L2:L6L2=IF(K2="","",IF(COUNT(K$2:K2)=COUNTA(A$2:A$100),ROWS(A$2:A$100),K3-1))
M2:M6M2=IF(K2="","",INDEX(A$2:A$100,K2))
N2:N6N2=IF(K2="","",MAX(INDEX(I$2:I$100,K2):INDEX(I$2:I$100,L2)))
O2:R6O2=IF($K2="","",IFERROR(INDEX($E:$E,AGGREGATE(15,6,ROW(INDEX($E$2:$E$100,$K2):INDEX($E$2:$E$100,$L2))/(INDEX($I$2:$I$100,$K2):INDEX($I$2:$I$100,$L2)=$N2),COLUMNS($O2:O2))),""))
 
Upvote 0
Hello,
This is the screen-shot of actual data

Col1 to col9 have few merged cells.

Columns are hidden from I to O because they are of no use here.

Col1 has some ID’s.


Now for a given ID in col1, I have to find the largest number from col15.

Once I have the cell with largest value selected, I want to have the corresponding value from col7.

For example in this screenshot, for given particular ID from col1, the largest value is $44,532 in last column(col15) so the output would be

“I47 PAROXYSMAL TACHYCARDIA” from col7.

Please let me know in case of any information required.
screenshot1.PNG
 
Upvote 0
In fact, in your image, the highest value for the ID from col1 is $ 47,379.
Which means another consideration.

And the result, do you still want it in a msgbox?
 
Upvote 0
thank you for putting that point.
47379 is total of all values so we have to exclude it
you can consider the second largest value from that range
msgbox or into cell
anything would work for me
 
Upvote 0
If it is in a cell, in which cell? on which sheet?
And returning to Peter's question, what happens, if there are two or more maximum equal values?
That is, in total 80,000 and two values with 40,000, what would you do?

In your image you only put one ID, but do you have more ID? And I guess you also want the values of each ID?
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,972
Members
452,540
Latest member
haasro02

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