Avatar of Luis Diaz
Luis Diaz
Flag for Colombia

asked on 

Excel VBA: apply specific format

Hello experts,
I have the following code in order to apply format for for specific range.
I would like to create an Apply_Format procedure to add to my personal.xlsb with the following requirement:
1.      Inputbox: “Select initial range (header range) in which you want to apply format”. Error handling: exit sub if the data reported is not correct or exit sub if cancel button is activated.
Here is what I have for the moment:

Sub Apply_Format()
Dim wb As Workbook
Dim ws As Worksheet
Dim iX As Integer

Set ws = ActiveSheet
With ws
'Remove gridlines
ActiveWindow.DisplayGridlines = False
'Apply Borders
With .Borders
.LineStyle = xlContinuous
.ThemeColor = 7
.TintAndShade = 0
.Weight = xlThin
End With
'Apply Font
With .Font
.Name = "Segoe UI"
.Size = 11
End With
'Set columns width
For iX = 1 To tbl.ListColumns.Count
tbl.ListColumns(iX).Range.ColumnWidth = 20
Next iX

'Apply Alignement
With .HorizontalAlignment = xlLeft
End With
End With
'Apply fill color for header row
'With .HeaderRowRange
With .Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 26112
.TintAndShade = 0
.PatternTintAndShade = 0
End With
'Apply font white
With .Font
.Color = vbWhite
.Name = "Segoe UI"
End With
End With
End Sub

Open in new window

VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Steve Knight

8/22/2022 - Mon