0

The code I have below applies to all worksheets in a blank workbook. But when I add the same code to an existing workbook which has a 60pg macro (no code has been established for Font though in those 60pgs.), the code applies to worksheet 1 alone. Not to the other worksheets. How can I edit the code below to apply to all worksheets in the workbook w/o altering the existing macro? Kindly help.

Dim r As Range
Set r = Range("a1:i1")
r.Font.Bold = True
r.Font.Name = "Segoe UI Symbol"
r.Font.Size = 14
Set r = Range("a2:i100")
r.Font.Bold = True
r.Font.Name = "Segoe UI Symbol"
r.Font.Size = 11
'End Sub

End Sub

This code works. But is simply not applying to all worksheets except the first one.

Chrismas007
  • 6,085
  • 4
  • 24
  • 47
  • r is a range not a workbook, and you will need to loop through all the sheets. there are many example on this site alone that will help you do that. – Scott Craner Jan 19 '17 at 20:49
  • Thank you @ScottCraner . I made a mistake with the workbook part. I meant range. – Nabeela Van Jan 19 '17 at 20:51

1 Answers1

0
Option Explicit

Sub test()
Dim r As Range
Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
    Set r = sh.Range("a1:i1")
    r.Font.Bold = True
    r.Font.Name = "Segoe UI Symbol"
    r.Font.Size = 14
    Set r = sh.Range("a2:i100")
    r.Font.Bold = True
    r.Font.Name = "Segoe UI Symbol"
    r.Font.Size = 11
Next sh
End Sub
D. O.
  • 616
  • 1
  • 11
  • 25