I created a sheet with merged cells, but the value of the merged cells is only stored in the first cell. Is there anyway, to keep the same value in each of the cells, I need that for a formula I use. Thanks!
You could use a custom VBA function that gives directly the value of the merged cell, no matter which one you select. In that case it is not necessary to duplicate the values.
Code:
Option Explicit
Function GetMergedValue(location As Range)
If location.MergeCells = True Then
GetMergedValue = location.MergeArea(1, 1)
Else
GetMergedValue = location
End If
End Function
Code:
=GetMergedValue(A1)
Where A1 is a part of a merged cell.
In Excel 2003 this macro does the job:
Public Sub UnmergeAndFill()
With Selection
If .MergeCells Then
.MergeCells = False
Selection.Cells(1, 1).Copy
ActiveSheet.Paste 'Or PasteSpecial xlPasteFormulasAndNumberFormats
End If
End With
End Sub
Create the macro by
Insert/Module
, paste the code;UnmergeAndFill
, e.g.), click Make
or Create
(? don't know the English button text)Invoke the Macro by pressing Alt-F8, select it, Run
. Alternatively map it to a key
I know this is a rather old question, but this is the first place I landed when looking for an answer, and the accepted answer did not help at all. I DID discover an excellent answer, however, on MrExcel which I thought was worth putting on this thread for the benefit of anyone else googling for an answer:
http://www.mrexcel.com/forum/general-excel-discussion-other-questions/487941-data-multiple-cells-within-merged-cell-possible.html
To save looking up the link, the answer is remarkably simple; if you merge cells using Excel Format Painter, rather than Merge Cells, it preserves the data/formulae 'underlying' the merged cells. You just need to create a temporary merged block of cells in the right format somewhere else, to use as a template for the Format Painter. You can delete them afterwards. One thing to watch out for, though, is having 'hidden' data like this can be a trap for the unwary, since editing the visible cell does not change the invisible ones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With