![]() |
|
#2
|
||||
|
||||
|
This sort of thing occurs when there is phantom data in cells not used for the merge (maybe a space that is difficult to spot). The following Excel macro should enable you to clean up the worksheet to avoid the problem. Certainly it fixes the problem on the example sheet you provided.
Code:
Option Explicit
Sub CleanSheet()
Dim xlSheet As Object
Dim iCols As Long, iCol As Long, c As Long
Dim iRows As Long, iRow As Long, r As Long
Set xlSheet = ActiveSheet
iRows = xlSheet.UsedRange.Rows.Count
iCols = xlSheet.UsedRange.Columns.Count
iRow = xlSheet.Cells(xlSheet.Rows.Count, 1).End(-4162).Row
iCol = xlSheet.Cells(1, xlSheet.Columns.Count).End(-4159).Column
If iRows > iRow Then
For r = iRows To iRow + 1 Step -1
xlSheet.Rows(r).EntireRow.Delete
DoEvents
Next r
End If
If iCols > iCol Then
For c = iCols To iCol + 1 Step -1
xlSheet.Columns(c).EntireColumn.Delete
DoEvents
Next c
End If
Set xlSheet = Nothing
lbl_Exit:
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do I output text to a specific cell (x,y)? | norwood | Word VBA | 2 | 01-31-2014 08:43 AM |
| Fix data output position relative to page | Al See | Mail Merge | 1 | 01-16-2014 04:13 PM |
| mail merge – output to .pdf | eNGiNe | Mail Merge | 3 | 09-29-2013 11:45 PM |
Input from excel, output to word
|
conradin | Word | 3 | 04-20-2011 07:48 PM |
| Output Presentation Settings | yeapurvz10 | PowerPoint | 0 | 09-17-2010 10:30 AM |