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

Hasson

Active Member
Joined
Apr 8, 2021
Messages
291
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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

sarathc

New Member
Joined
Mar 30, 2022
Messages
14
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
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.
 

Hasson

Active Member
Joined
Apr 8, 2021
Messages
291
Office Version
  1. 2016
Platform
  1. Windows
thanks for this , but it deletes borders !!
 

sarathc

New Member
Joined
Mar 30, 2022
Messages
14
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
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
 

Hasson

Active Member
Joined
Apr 8, 2021
Messages
291
Office Version
  1. 2016
Platform
  1. Windows
If you don't want to remove borders
NO NO ! I don't want it . I would keep it .
 

sarathc

New Member
Joined
Mar 30, 2022
Messages
14
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
If you want the borders as it is in your file, use second code. If you wanna remove those border, use first code.
 

Hasson

Active Member
Joined
Apr 8, 2021
Messages
291
Office Version
  1. 2016
Platform
  1. Windows
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
 

Forum statistics

Threads
1,176,090
Messages
5,901,352
Members
434,887
Latest member
zoath

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
Top