Hi, mathmani,
wouldnīit be a great idea to share all the code you have so far and not only a sniplet which canīt work due to a missing opening bracket (check the formula inserted manually where 2 opening brackets appear against the code) and only one item in a list referred to?
Maybe you can use the approach like this:
Private Sub FindUniqueItems(UniqueItems As Variant, FilterRange As String)
' returns a list containing all unique items in the filter range
' Originally taken from ErlandsenData, modified for ExcelForum
Dim TempList() As String, UniqueCount As Integer, cl As Range, i As Integer
Range(FilterRange).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
UniqueCount = Range(FilterRange).SpecialCells(xlCellTypeVisible).Count
ReDim TempList(1 To UniqueCount - 1)
i = 0
For Each cl In Range(FilterRange).SpecialCells(xlCellTypeVisible)
If Len(cl) > 0 Then
i = i + 1
If i > 1 Then TempList(i - 1) = cl.Formula ' ignore the heading
End If
Next cl
ReDim Preserve TempList(1 To i - 1)
Set cl = Nothing
UniqueItems = TempList
ActiveSheet.ShowAllData
End Sub
Sub Still_Dont_Like_Merged_Cells()
Dim ItemListA
Dim ItemListC
Dim lngColA As Long
Dim lngColC As Long
Dim lngLastRow As Long
Dim lngRngUsed As Long
Dim lngOffset As Long
Dim rngMerged As Range
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
lngRngUsed = lngLastRow - 1
FindUniqueItems ItemListA, Range("A2:A" & lngRngUsed).Address
FindUniqueItems ItemListC, Range("C2:C" & lngRngUsed).Address
Range("D1").Select
Do While ActiveCell.Value <> ""
Set rngMerged = ActiveCell.MergeArea
If rngMerged.Cells.Count > 0 Then
lngOffset = 1
For lngColA = LBound(ItemListA) To UBound(ItemListA)
For lngColC = LBound(ItemListC) To UBound(ItemListC)
Cells(lngLastRow + lngOffset, rngMerged.Cells(1).Column).Formula = "=SUMPRODUCT((" & Cells(3, rngMerged.Cells(1).Column).Address(0, 0) & ":" & _
Cells(lngRngUsed, rngMerged.Cells(rngMerged.Cells.Count).Column).Address(0, 0) & ")*($A$3:$A$" & lngRngUsed & "=""" & ItemListA(lngColA) & _
""")*($C$3:$C$" & lngRngUsed & "=""" & ItemListC(lngColC) & """))"
lngOffset = lngOffset + 1
Next lngColC
Next lngColA
End If
ActiveCell.Offset(0, 1).Select
Loop
End Sub
Ciao,
Holger
Bookmarks