1

I have code that is printing text into a given set of cells as shown below:

'SAMPLE
Sheets("Sheet1").Range("A11") = "B. TEST SAMPLES"
Sheets("Sheet1").Range("B12") = "SS"
Sheets("Sheet1").Range("C12") = "PART NO."
Sheets("Sheet1").Range("C12:H12").Merge
Sheets("Sheet1").Range("C12:H12").HorizontalAlignment = xlCenter
Sheets("Sheet1").Range("I12") = "VALVE CODE"
Sheets("Sheet1").Range("I12:M12").Merge
Sheets("Sheet1").Range("I12:M12").HorizontalAlignment = xlCenter
Sheets("Sheet1").Range("N12") = "TYPE"
Sheets("Sheet1").Range("N12:P12").Merge
Sheets("Sheet1").Range("N12:P12").HorizontalAlignment = xlCenter
Sheets("Sheet1").Range("Q12") = "TA/SEALED"
Sheets("Sheet1").Range("Q12:T12").Merge
Sheets("Sheet1").Range("Q12:T12").HorizontalAlignment = xlCenter
Sheets("Sheet1").Range("U12") = "Qt"
Sheets("Sheet1").Range("V12") = "Spring"
Sheets("Sheet1").Range("V12:X12").Merge
Sheets("Sheet1").Range("V12:X12").HorizontalAlignment = xlCenter
Sheets("Sheet1").Range("Y12") = "DESCRIPTION"

It does this perfectly, now I want to bold the top cells. I write the following code to achieve this:

'FORMATTING
Range("B12").Font.Bold = True
Range("C12").Font.Bold = True
Range("I12").Font.Bold = True
Range("N12").Font.Bold = True
Range("Q12").Font.Bold = True
Range("U12").Font.Bold = True
Range("V12").Font.Bold = True
Range("Y12").Font.Bold = True

I do not see anything wrong with this code, the syntax seems fine but the formatting is not changed. ie. The cells I want bolded remain unbolded.

Could anyone provide some insight on why this is happening and how it can possibly be fixed?

2
  • The first part of your code references the sheet name "Sheet1". Is this the active sheet when you run your code? Commented Jul 21, 2015 at 19:02
  • 2
    Are you leaving out Sheets("Sheet1"). from all of them? Commented Jul 21, 2015 at 19:02

3 Answers 3

2

Make sure you have Sheets("Sheet1") before Range().Font.Bold = True

Sign up to request clarification or add additional context in comments.

Comments

1

Here is the working code:

Sheets("Sheet1").Select

Range("B12","C12","I12","N12","Q12","U12","V12","Y12").Font.Bold = True  

You can select all your cells in one range.

1 Comment

Better not to use select - skip that word completely and you can just use Sheets("Sheet1").Range("B12","C12",...).Font.Bold = True
0

Is there are reason you didn't use sheets("")

'FORMATTING
Sheets("Sheet1").Range("B12").Font.Bold = True
Sheets("Sheet1").Range("C12").Font.Bold = True
Sheets("Sheet1").Range("I12").Font.Bold = True
Sheets("Sheet1").Range("N12").Font.Bold = True

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.