This project has moved. For the latest updates, please go here.

How to write to a merged cell

Mar 22, 2016 at 4:00 AM
Edited Mar 22, 2016 at 4:01 AM
i am trying to replace some string literals in merged cells with their actual values,
Did following but neither its working nor throwing any error. Please help
** I am able to read the merged cell contained but cant write to it.
For Each mc As String In ws.MergedCells
            Dim s As String = ws.Cells(mc).Value(0, 0)
            If String.IsNullOrEmpty(s) Then Continue For

            If s.StartsWith("{") AndAlso s.EndsWith("}") Then
                If dicKeyValue.ContainsKey(s) Then
                    ws.Cells(mc).Value(0, 0) = dicKeyValue(s)
                End If
            End If
        Next
Mar 22, 2016 at 4:25 AM
found the issue, following is working for me, sorry to put the question in hurry without enough research:
For Each mc In ws.MergedCells
            Dim s As String = ws.Cells(mc).Value(0, 0)
            If String.IsNullOrEmpty(s) Then Continue For

            If s.StartsWith("{") AndAlso s.EndsWith("}") Then
                If dicKeyValue.ContainsKey(s) Then
                    Dim arr() As String = mc.Split(":")
                    ws.SetValue(arr(0), dicKeyValue(s))
                End If
            End If
        Next
Marked as answer by ManuBhai on 3/21/2016 at 9:25 PM