Merge a number of cells based on a numeric value in 3rd cell

L

Legacy 223018

Guest
Hi there,

I'm trying something new to me in Excel using VBA:

The base of data is a table with a fixed number of market segments. For each segment there is the same list of competitors (text values). The length of the list may vary as it is created by another macro. Associated to each segment there is the market share per competitor (numeric values). The total of each market share column is always 100%.

The second part of the worksheet is a range of exactly 100 empty lines pre-formatted into very low row height (3.0).

Here the example:
[TABLE="class: outer_border, width: 500"]
<tbody>[TR]
[TD]Segment1
[/TD]
[TD]Market Share1
[/TD]
[TD]Segment2
[/TD]
[TD]Market Share2
[/TD]
[/TR]
[TR]
[TD]Firm1
[/TD]
[TD]0%
[/TD]
[TD]Firm1
[/TD]
[TD]30%
[/TD]
[/TR]
[TR]
[TD]Firm2
[/TD]
[TD]20%
[/TD]
[TD]Firm2
[/TD]
[TD]10%
[/TD]
[/TR]
[TR]
[TD]Firm3
[/TD]
[TD]10%
[/TD]
[TD]Firm3
[/TD]
[TD]0%
[/TD]
[/TR]
[TR]
[TD]Firm4
[/TD]
[TD]10%
[/TD]
[TD]Firm4
[/TD]
[TD]0%
[/TD]
[/TR]
[TR]
[TD]Firm5
[/TD]
[TD]50%
[/TD]
[TD]Firm5
[/TD]
[TD]0%
[/TD]
[/TR]
[TR]
[TD]Firm6
[/TD]
[TD]0%
[/TD]
[TD]Firm6
[/TD]
[TD]30%
[/TD]
[/TR]
[TR]
[TD]Firm7
[/TD]
[TD]10%
[/TD]
[TD]Firm7
[/TD]
[TD]30%
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Segment1
[/TD]
[TD][/TD]
[TD]Segment2
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]100 lines
[/TD]
[TD][/TD]
[TD]100 lines
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

What I would like to do with this:

For each per cent of market share I would like to assign 1 line in the second part of the worksheet to a competitor. For example, for a competitor's market share in segment 1 of 10% I would need to assign 10 cells to the competitor in the to be created table below and merge them into one. In this part of the worksheet column B has no function. In column C this same procedure will have to be done for segment 2.
After merging the cells into the newly created single one, the latter should contain the text value which is the name of the firm x and its market share in %. Obviously only cells that have not been merged, yet, should be considered. At the end all 100 lines should have been treated by the macro.

The whole thing in theory corresponds to the automatic creation of a 100% stacked column chart but for company internal reasons related to how I present the data, I cannot use that chart type.

As of now I have only (in my opinion) useless bits of code. So I won't post it here. What I have particular problems with is to imagine how I can use a numeric value x, then to select a range of cells y (where x = y) and merge them.

Any ideas how to get me started? :confused:

Thanks a lot in advance!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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