Hello. Is it possible to merge cells in a column based on already merged cells from another column? I have a column that has merged cells using the code below. I now want to merge the columns next to this column to group the merged cells.
Column H is run by the code below. I want to also merge cells in Column F and G that match the same merge as column H. The merge needs to be based off of column H though.
Any help is much appreciated.
This is what it looks like now:
This is what I want it to look like:
Code for merging Comps:
Sub MergeSameCells()
Application.DisplayAlerts = False
Dim rng As Range
MergeCells:
For Each rng In Selection
If rng.Value = rng.Offset(1, 0).Value And rng.Value <> "" Then
Range(rng, rng.Offset(1, 0)).Merge
Range(rng, rng.Offset(1, 0)).HorizontalAlignment = xlCenter
Range(rng, rng.Offset(1, 0)).VerticalAlignment = xlCenter
GoTo MergeCells
End If
Next
End Sub
Column H is run by the code below. I want to also merge cells in Column F and G that match the same merge as column H. The merge needs to be based off of column H though.
Any help is much appreciated.
This is what it looks like now:
This is what I want it to look like:
Code for merging Comps:
Sub MergeSameCells()
Application.DisplayAlerts = False
Dim rng As Range
MergeCells:
For Each rng In Selection
If rng.Value = rng.Offset(1, 0).Value And rng.Value <> "" Then
Range(rng, rng.Offset(1, 0)).Merge
Range(rng, rng.Offset(1, 0)).HorizontalAlignment = xlCenter
Range(rng, rng.Offset(1, 0)).VerticalAlignment = xlCenter
GoTo MergeCells
End If
Next
End Sub
lookup.xlsx | |||||
---|---|---|---|---|---|
F | G | H | |||
1 | Pulp_Composite_for_ME | ME_Analysis_Code | New_Composite_Sample_ID | ||
2 | DO NOT INCLUDE IN COMPOSITE | DO NOT INCLUDE IN COMPOSITE | DO NOT USE IN COMPOSITE | ||
3 | Composite Pulp for ME | ME-MS41 | MZ22-01_0-20_COMP | ||
4 | Composite Pulp for ME | ME-MS41 | |||
5 | Composite Pulp for ME | ME-MS41 | |||
6 | Composite Pulp for ME | ME-MS41 | |||
7 | Composite Pulp for ME | ME-MS41 | MZ22-01_20-40_COMP | ||
8 | Composite Pulp for ME | ME-MS41 | |||
9 | Composite Pulp for ME | ME-MS41 | |||
10 | Composite Pulp for ME | ME-MS41 | |||
11 | Composite Pulp for ME | ME-MS41 | MZ22-01_40-55_COMP | ||
12 | Composite Pulp for ME | ME-MS41 | |||
13 | DO NOT INCLUDE IN COMPOSITE | DO NOT INCLUDE IN COMPOSITE | DO NOT USE IN COMPOSITE | ||
14 | Composite Pulp for ME | ME-MS41 | MZ22-01_40-55_COMP | ||
15 | Composite Pulp for ME | ME-MS41 | MZ22-01_55-70_COMP | ||
16 | Composite Pulp for ME | ME-MS41 | |||
17 | Composite Pulp for ME | ME-MS41 | |||
18 | Composite Pulp for ME | ME-MS41 | MZ22-01_70-85_COMP | ||
19 | Composite Pulp for ME | ME-MS41 | |||
20 | Composite Pulp for ME | ME-MS41 | |||
21 | Composite Pulp for ME | ME-MS41 | MZ22-01_85-100_COMP | ||
22 | Composite Pulp for ME | ME-MS41 | |||
23 | Composite Pulp for ME | ME-MS41 | |||
24 | DO NOT INCLUDE IN COMPOSITE | DO NOT INCLUDE IN COMPOSITE | DO NOT USE IN COMPOSITE | ||
25 | Composite Pulp for ME | ME-MS41 | MZ22-01_100-120_COMP | ||
26 | Composite Pulp for ME | ME-MS41 | |||
27 | Composite Pulp for ME | ME-MS41 | |||
28 | Composite Pulp for ME | ME-MS41 | |||
29 | Composite Pulp for ME | ME-MS42 | MZ22-01_120-140_COMP | ||
30 | Composite Pulp for ME | ME-MS43 | |||
31 | Composite Pulp for ME | ME-MS44 | |||
32 | Composite Pulp for ME | ME-MS45 | |||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
H2,H24,H13 | H2 | =IFERROR(XLOOKUP(SUBSTITUTE(RIGHT(A2,LEN(A2)-FIND("_",A2)),"-",".")*1,SUBSTITUTE(RIGHT('[Britt Test Sample Submittal GF (version 1).xlsb1.xlsm]Composites'!M:M,LEN('[Britt Test Sample Submittal GF (version 1).xlsb1.xlsm]Composites'!M:M)-FIND("_",'[Britt Test Sample Submittal GF (version 1).xlsb1.xlsm]Composites'!M:M)),"-",".")*1,'[Britt Test Sample Submittal GF (version 1).xlsb1.xlsm]Composites'!E:E,"DO NOT USE IN COMPOSITE",-1),"DO NOT USE IN COMPOSITE") |