Formatting Excel Spreadsheet with VBA

 

Although you can use many formatting tools  in MS Excel, it is still better to program certain formatting VBAs so that it can automates as well  speeds up the formatting jobs. In this program, I have program a few formatting tools that are able to change case and to manipulate the fonts. Below are the sample programs:

 

Program to change to upper case

Private Sub CommandButton1_Click()

Dim rng, cell As Range, selectedRng, cell_value As String
selectedRng = InputBox("Enter your range (Using the format Ai:Aj)")
Set rng = Range(selectedRng)
For Each cell In rng
cell_value = UCase(cell.Value)
cell.Value = cell_value
Next cell
End Sub


Program to change to lower case



Private Sub CommandButton2_Click()
Dim rng, cell As Range, selectedRng, cell_value As String
selectedRng = InputBox("Enter your range (Using the format Ai:Aj)")
Set rng = Range(selectedRng)
For Each cell In rng
cell_value = LCase(cell.Value)
cell.Value = cell_value

Next cell

End Sub

 

Program to change to italic fonts

Private Sub CommandButton3_Click()
Dim rng, cell As Range, selectedRng, cell_value As String
selectedRng = InputBox("Enter your range (Using the format Ai:Aj)")
Set rng = Range(selectedRng)
rng.Font.Italic = True
End Sub

                      

Program to change to  bold fonts

Private Sub CommandButton4_Click()
Dim rng, cell As Range, selectedRng, cell_value As String
selectedRng = InputBox("Enter your range (Using the format Ai:Aj)")
Set rng = Range(selectedRng)
rng.Font.Bold = True
End Sub

Private Sub CommandButton5_Click()
Dim rng, cell As Range, selectedRng, cell_value As String
selectedRng = InputBox("Enter your range (Using the format Ai:Aj)")
Set rng = Range(selectedRng)
rng.Font.Underline = True
End Sub

 

 

 

 

 

 [Back to VBToday]