Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How can I unmerge the merged cells in a Excel sheet quickly?

I want a function like this:
to unmerge all merged cells in a Excel sheet and replaced all the merged
cells value with the originally merged area value after unmerging action.

I use the a cycle to fulfill it. But it's too too slowly if the Excel sheet
data is a little big. The code (c# code) as below:

for (int i=1; i<=Int32.Parse(ws.UsedRange.Rows.Count.ToString()) ;i++)
{
for (int j=1; j<=Int32.Parse(ws.UsedRange.Columns.Count.ToString ()); j++)
{
Excel.Range Range = (Excel.Range)ws.Cells[i,j];


if (bool.Parse(Range.MergeCells.ToString()))
{
int x = Int32.Parse(Range.MergeArea.Rows.Count.ToString()) ;
int y = Int32.Parse(Range.MergeArea.Columns.Count.ToString ());
string TempValue = Range.Text.ToString();

Range.MergeArea.UnMerge();

for (int m = i; m<(i+x); m++)
{
for (int n = j; n<(j+y); n++)
{
Excel.Range TempRange = (Excel.Range)ws.Cells[m,n];
TempRange.set_Value( Type.Missing,TempValue);
}
}
}

}
}


Does Somebody have another idea to do it quickly??
Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How can I unmerge the merged cells in a Excel sheet quickly?

Pls help me :)

"Tomorrow" wrote:

I want a function like this:
to unmerge all merged cells in a Excel sheet and replaced all the merged
cells value with the originally merged area value after unmerging action.

I use the a cycle to fulfill it. But it's too too slowly if the Excel sheet
data is a little big. The code (c# code) as below:

for (int i=1; i<=Int32.Parse(ws.UsedRange.Rows.Count.ToString()) ;i++)
{
for (int j=1; j<=Int32.Parse(ws.UsedRange.Columns.Count.ToString ()); j++)
{
Excel.Range Range = (Excel.Range)ws.Cells[i,j];


if (bool.Parse(Range.MergeCells.ToString()))
{
int x = Int32.Parse(Range.MergeArea.Rows.Count.ToString()) ;
int y = Int32.Parse(Range.MergeArea.Columns.Count.ToString ());
string TempValue = Range.Text.ToString();

Range.MergeArea.UnMerge();

for (int m = i; m<(i+x); m++)
{
for (int n = j; n<(j+y); n++)
{
Excel.Range TempRange = (Excel.Range)ws.Cells[m,n];
TempRange.set_Value( Type.Missing,TempValue);
}
}
}

}
}


Does Somebody have another idea to do it quickly??
Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default How can I unmerge the merged cells in a Excel sheet quickly?

Why can't you just select all cells in the sheet (small square that
intersects headers), Format cells Alignment and untick the Merge cells box
(may need to click it twice). Record a macro for the code.

Regards,
Peter

"Tomorrow" wrote in message
...
Pls help me :)

"Tomorrow" wrote:

I want a function like this:
to unmerge all merged cells in a Excel sheet and replaced all the merged
cells value with the originally merged area value after unmerging

action.

I use the a cycle to fulfill it. But it's too too slowly if the Excel

sheet
data is a little big. The code (c# code) as below:

for (int i=1; i<=Int32.Parse(ws.UsedRange.Rows.Count.ToString()) ;i++)
{
for (int j=1; j<=Int32.Parse(ws.UsedRange.Columns.Count.ToString ());

j++)
{
Excel.Range Range = (Excel.Range)ws.Cells[i,j];


if (bool.Parse(Range.MergeCells.ToString()))
{
int x = Int32.Parse(Range.MergeArea.Rows.Count.ToString()) ;
int y = Int32.Parse(Range.MergeArea.Columns.Count.ToString ());
string TempValue = Range.Text.ToString();

Range.MergeArea.UnMerge();

for (int m = i; m<(i+x); m++)
{
for (int n = j; n<(j+y); n++)
{
Excel.Range TempRange = (Excel.Range)ws.Cells[m,n];
TempRange.set_Value( Type.Missing,TempValue);
}
}
}

}
}


Does Somebody have another idea to do it quickly??
Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How can I unmerge the merged cells in a Excel sheet quickly?

Thanks, Peter:
I tried the method you told below, but I can't read the all merged areas
data(not only one merged area). The Macro code as below:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 10/21/2004 by Tomorrow
'

'
Range("A1:AU138").Select
Range("AB120").Activate
With Selection
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub

Best regards,
Tomorrow

"Peter T" wrote:

Why can't you just select all cells in the sheet (small square that
intersects headers), Format cells Alignment and untick the Merge cells box
(may need to click it twice). Record a macro for the code.

Regards,
Peter

"Tomorrow" wrote in message
...
Pls help me :)

"Tomorrow" wrote:

I want a function like this:
to unmerge all merged cells in a Excel sheet and replaced all the merged
cells value with the originally merged area value after unmerging

action.

I use the a cycle to fulfill it. But it's too too slowly if the Excel

sheet
data is a little big. The code (c# code) as below:

for (int i=1; i<=Int32.Parse(ws.UsedRange.Rows.Count.ToString()) ;i++)
{
for (int j=1; j<=Int32.Parse(ws.UsedRange.Columns.Count.ToString ());

j++)
{
Excel.Range Range = (Excel.Range)ws.Cells[i,j];


if (bool.Parse(Range.MergeCells.ToString()))
{
int x = Int32.Parse(Range.MergeArea.Rows.Count.ToString()) ;
int y = Int32.Parse(Range.MergeArea.Columns.Count.ToString ());
string TempValue = Range.Text.ToString();

Range.MergeArea.UnMerge();

for (int m = i; m<(i+x); m++)
{
for (int n = j; n<(j+y); n++)
{
Excel.Range TempRange = (Excel.Range)ws.Cells[m,n];
TempRange.set_Value( Type.Missing,TempValue);
}
}
}

}
}


Does Somebody have another idea to do it quickly??
Thanks.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default How can I unmerge the merged cells in a Excel sheet quickly?

I might have misunderstood your original question, are you saying you want
to do something like this:

- First merged area is (say) B2:B5 and B2 contains value "X" (only B2 can
contain data)
- Unmerge B2:B5 and put "X" in the other 7 cells.
- Do similar with all merged areas on the sheet

Sub TestUnmerge()
Dim r As Range, rMgArea As Range

For Each r In ActiveSheet.UsedRange
If r.MergeArea.Cells.Count 1 Then
Set rMgArea = r.MergeArea
r.UnMerge
rMgArea.Value = r.Value
End If
Next

End Sub

This assumes by "value" you mean constants and not formulas. If not above
would need to be changed.

Regards,
Peter

"Tomorrow" wrote in message
...
Thanks, Peter:
I tried the method you told below, but I can't read the all merged areas
data(not only one merged area). The Macro code as below:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 10/21/2004 by Tomorrow
'

'
Range("A1:AU138").Select
Range("AB120").Activate
With Selection
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub

Best regards,
Tomorrow

"Peter T" wrote:

Why can't you just select all cells in the sheet (small square that
intersects headers), Format cells Alignment and untick the Merge cells

box
(may need to click it twice). Record a macro for the code.

Regards,
Peter

"Tomorrow" wrote in message
...
Pls help me :)

"Tomorrow" wrote:

I want a function like this:
to unmerge all merged cells in a Excel sheet and replaced all the

merged
cells value with the originally merged area value after unmerging

action.

I use the a cycle to fulfill it. But it's too too slowly if the

Excel
sheet
data is a little big. The code (c# code) as below:

for (int i=1;

i<=Int32.Parse(ws.UsedRange.Rows.Count.ToString()) ;i++)
{
for (int j=1; j<=Int32.Parse(ws.UsedRange.Columns.Count.ToString ());

j++)
{
Excel.Range Range = (Excel.Range)ws.Cells[i,j];


if (bool.Parse(Range.MergeCells.ToString()))
{
int x = Int32.Parse(Range.MergeArea.Rows.Count.ToString()) ;
int y = Int32.Parse(Range.MergeArea.Columns.Count.ToString ());
string TempValue = Range.Text.ToString();

Range.MergeArea.UnMerge();

for (int m = i; m<(i+x); m++)
{
for (int n = j; n<(j+y); n++)
{
Excel.Range TempRange = (Excel.Range)ws.Cells[m,n];
TempRange.set_Value( Type.Missing,TempValue);
}
}
}

}
}


Does Somebody have another idea to do it quickly??
Thanks.








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How can I unmerge the merged cells in a Excel sheet quickly?

Thaks, Peter:
Yeah, I want function just like that you said below. I had tried the
method you teached, but it can't work. The error means that can't find the
Range obeject with which use the foreach sentence. Did you work ok?

Regards,
Tomorrow


"Peter T" wrote:

I might have misunderstood your original question, are you saying you want
to do something like this:

- First merged area is (say) B2:B5 and B2 contains value "X" (only B2 can
contain data)
- Unmerge B2:B5 and put "X" in the other 7 cells.
- Do similar with all merged areas on the sheet

Sub TestUnmerge()
Dim r As Range, rMgArea As Range

For Each r In ActiveSheet.UsedRange
If r.MergeArea.Cells.Count 1 Then
Set rMgArea = r.MergeArea
r.UnMerge
rMgArea.Value = r.Value
End If
Next

End Sub

This assumes by "value" you mean constants and not formulas. If not above
would need to be changed.

Regards,
Peter

"Tomorrow" wrote in message
...
Thanks, Peter:
I tried the method you told below, but I can't read the all merged areas
data(not only one merged area). The Macro code as below:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 10/21/2004 by Tomorrow
'

'
Range("A1:AU138").Select
Range("AB120").Activate
With Selection
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub

Best regards,
Tomorrow

"Peter T" wrote:

Why can't you just select all cells in the sheet (small square that
intersects headers), Format cells Alignment and untick the Merge cells

box
(may need to click it twice). Record a macro for the code.

Regards,
Peter

"Tomorrow" wrote in message
...
Pls help me :)

"Tomorrow" wrote:

I want a function like this:
to unmerge all merged cells in a Excel sheet and replaced all the

merged
cells value with the originally merged area value after unmerging
action.

I use the a cycle to fulfill it. But it's too too slowly if the

Excel
sheet
data is a little big. The code (c# code) as below:

for (int i=1;

i<=Int32.Parse(ws.UsedRange.Rows.Count.ToString()) ;i++)
{
for (int j=1; j<=Int32.Parse(ws.UsedRange.Columns.Count.ToString ());
j++)
{
Excel.Range Range = (Excel.Range)ws.Cells[i,j];


if (bool.Parse(Range.MergeCells.ToString()))
{
int x = Int32.Parse(Range.MergeArea.Rows.Count.ToString()) ;
int y = Int32.Parse(Range.MergeArea.Columns.Count.ToString ());
string TempValue = Range.Text.ToString();

Range.MergeArea.UnMerge();

for (int m = i; m<(i+x); m++)
{
for (int n = j; n<(j+y); n++)
{
Excel.Range TempRange = (Excel.Range)ws.Cells[m,n];
TempRange.set_Value( Type.Missing,TempValue);
}
}
}

}
}


Does Somebody have another idea to do it quickly??
Thanks.






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
how do I unmerge an entire spread sheet in excel? Wendy Excel Worksheet Functions 1 January 30th 10 03:39 PM
sort spreadsheet, "merged cells" comes up. Find cells? Unmerge ? lowell Excel Discussion (Misc queries) 1 August 20th 06 09:10 AM
Cannot merge or unmerge cells in Excel Tara Excel Discussion (Misc queries) 2 July 5th 06 09:30 PM
UNMERGE two cells/rows in Excel Larry D. Excel Discussion (Misc queries) 1 January 28th 05 09:00 PM
Can't unmerge merged cells programatically James[_29_] Excel Programming 1 September 14th 04 12:59 AM


All times are GMT +1. The time now is 03:59 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"