Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Losing "merge-cells" formatting when populating Worksheet from VBA


I have an Access application that is programmatically populating an
Excel spreadsheet via OLE (i.e. dim objXL as Excel.Application, set
objXl=CreateObject("excel.application") etc etc)

The application opens an existing xls file and then does a SaveAs so
the target is saved with a name reflecting it's contents e.g.
template=ApplicationTemplate.xls and the SaveAs destination is
Application123456.xls meaning data for application 123456 is contained
within it

When I go to populate a cell via something like a
"MyRange.Cells(a,b).Value = MyValue", the resulting spreadsheet has the
value OK but if that cell happened to have the "MergeCells" property set
i.e. it was merged with the 4 adjacent columns then this property has
been lost and I'm back to a single cell...

Is there a way I can programaticaly detect the merge cells properties
and then restore them or alternatively can I use the clipboard and do a
PasteSpecial for just the values in some way?

Any help or advice is appreciated

Cheers


--
Cardio
------------------------------------------------------------------------
Cardio's Profile: http://www.excelforum.com/member.php...o&userid=28976
View this thread: http://www.excelforum.com/showthread...hreadid=487076

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Losing "merge-cells" formatting when populating Worksheet from VBA

I couldn't duplicate this in xl2003. I used this (in the same instance of
excel):

Option Explicit
Sub testme()
Dim myRng As Range
Set myRng = ActiveSheet.Range("a1")
myRng.MergeArea.UnMerge
myRng.Resize(1, 5).Merge
Debug.Print ActiveSheet.Range("a1").MergeArea.Address & "<--before"
myRng.Value = "myValue"
Debug.Print ActiveSheet.Range("a1").MergeArea.Address & "<--after"
End Sub

I got this back in the immediate window:
$A$1:$E$1<--before
$A$1:$E$1<--after

And when I swapped back to excel A1:E1 were merged.

======
But a suggestion for a workaround--keep track of the range.

Option Explicit
Sub testme2()

Dim myRng As Range
Dim mySavedRng As Range

Set myRng = ActiveSheet.Range("a1")
myRng.MergeArea.UnMerge

myRng.Resize(1, 5).Merge

Set mySavedRng = myRng.MergeArea

'even if I do it myself
myRng.MergeArea.UnMerge
myRng.Value = "myValue"
'reapply the merge
mySavedRng.Merge
End Sub



Cardio wrote:

I have an Access application that is programmatically populating an
Excel spreadsheet via OLE (i.e. dim objXL as Excel.Application, set
objXl=CreateObject("excel.application") etc etc)

The application opens an existing xls file and then does a SaveAs so
the target is saved with a name reflecting it's contents e.g.
template=ApplicationTemplate.xls and the SaveAs destination is
Application123456.xls meaning data for application 123456 is contained
within it

When I go to populate a cell via something like a
"MyRange.Cells(a,b).Value = MyValue", the resulting spreadsheet has the
value OK but if that cell happened to have the "MergeCells" property set
i.e. it was merged with the 4 adjacent columns then this property has
been lost and I'm back to a single cell...

Is there a way I can programaticaly detect the merge cells properties
and then restore them or alternatively can I use the clipboard and do a
PasteSpecial for just the values in some way?

Any help or advice is appreciated

Cheers

--
Cardio
------------------------------------------------------------------------
Cardio's Profile: http://www.excelforum.com/member.php...o&userid=28976
View this thread: http://www.excelforum.com/showthread...hreadid=487076


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Center across selection" rather than "Merge cells" Elardus Excel Discussion (Misc queries) 10 November 6th 08 02:28 PM
is it possible to "merge" multiple worksheets into one worksheet? Jerry Bennett[_2_] Excel Discussion (Misc queries) 1 June 27th 08 06:31 PM
Can you merge cells in a "list"? Jules73 Excel Worksheet Functions 1 March 28th 07 02:57 AM
merge cells marco "help" BrianB Excel Programming 0 October 9th 03 09:11 AM
merge cells marco "help" Cliff Myers Excel Programming 0 October 9th 03 06:50 AM


All times are GMT +1. The time now is 11:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"