macro cancel merged cells & text wrap & autofit columns,rows into used range

Hasson

Active Member
Joined
Apr 8, 2021
Messages
401
Office Version
  1. 2016
Platform
  1. Windows
hello

I seek for macro to cancel any merged cell and delete text wrap( break line for each cell into columns or rows ) for each cells and autofit for all of the rows & columns and make the normal borders ,formatting .

because I convert the files PDF to EXCEL files when convert all of data ,then don't become arranging like merged cells , text wrap for each cell also the rows, columns are different in high and width sizes . so the macro should be( borders,formatting are normal , the cells are not merged, there is no break line for each cell into column or row , autofit rows , columns)
thanks
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You can use this.

Sub Formatting()
Cells.Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.UnMerge
Selection.RowHeight = 15
Selection.ColumnWidth = 8.11
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Cells.EntireColumn.AutoFit
End Sub

Let me know if anything more you need.
 
Upvote 0
Okay. If you don't want to remove borders, you can remove Selection.Borders commands from the code.

I will paste the updated code below:

VBA Code:
Sub Formatting()
Cells.Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.UnMerge
Selection.RowHeight = 15
Selection.ColumnWidth = 8.11
Cells.EntireColumn.AutoFit
End Sub
 
Upvote 0
If you want the borders as it is in your file, use second code. If you wanna remove those border, use first code.
 
Upvote 0
I made the code is short instead of using selection cells . I think this is better .
VBA Code:
Sub Formatting()

With sheet3.UsedRange
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
.UnMerge
.RowHeight = 15
.ColumnWidth = 8.11
Cells.EntireColumn.AutoFit
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top