C
Catalin Florean via OfficeKB.com
Hello,
I have a small VBA code that merge empty cell on each rows but keeping the columns.
For example the table:
---------------------
|A | B | C | D | |
---------------------
| | B | C | D | |
---------------------
| | B | C | D | |
---------------------
|A2| B2| C2| D2| |
---------------------
| | B2| C2| D2| |
---------------------
will be converted to
-------------------------
|A | BBB | CCC | DDD |
|A2| B2B2| C2C2| D2D2|
-------------------------
The problem is that it takes a very long time for tables with more than 50 rows.
Do you have any ideas on how to speed-up this macro?
Thank you,
Catalin Florean.
'My macro:
Sub tmpTable()
Application.ScreenUpdating = False
cateMerge = 0
Set myTable = ActiveDocument.Tables(1)
cateCol = myTable.Columns.Count
cateRow = myTable.Rows.Count
For currentRow = 1 To cateRow
If Len(myTable.Cell(currentRow, 1).Range.Text) <= 2 Then
cateMerge = cateMerge + 1
For j = 1 To cateCol - 1
myTable.Cell(currentRow, 0).Merge MergeTo:=myTable.Cell(currentRow - cateMerge, j)
Next j
Else
cateMerge = 0
End If
Next currentRow
myTable.Columns(cateCol).Delete
Application.ScreenUpdating = True
End Sub
I have a small VBA code that merge empty cell on each rows but keeping the columns.
For example the table:
---------------------
|A | B | C | D | |
---------------------
| | B | C | D | |
---------------------
| | B | C | D | |
---------------------
|A2| B2| C2| D2| |
---------------------
| | B2| C2| D2| |
---------------------
will be converted to
-------------------------
|A | BBB | CCC | DDD |
|A2| B2B2| C2C2| D2D2|
-------------------------
The problem is that it takes a very long time for tables with more than 50 rows.
Do you have any ideas on how to speed-up this macro?
Thank you,
Catalin Florean.
'My macro:
Sub tmpTable()
Application.ScreenUpdating = False
cateMerge = 0
Set myTable = ActiveDocument.Tables(1)
cateCol = myTable.Columns.Count
cateRow = myTable.Rows.Count
For currentRow = 1 To cateRow
If Len(myTable.Cell(currentRow, 1).Range.Text) <= 2 Then
cateMerge = cateMerge + 1
For j = 1 To cateCol - 1
myTable.Cell(currentRow, 0).Merge MergeTo:=myTable.Cell(currentRow - cateMerge, j)
Next j
Else
cateMerge = 0
End If
Next currentRow
myTable.Columns(cateCol).Delete
Application.ScreenUpdating = True
End Sub