Learn how to a build a cloud-first strategyRegister Now


Populate specific cells and address specific worksheets

Posted on 2012-09-20
Medium Priority
Last Modified: 2012-09-20
I have a macro that I'd like to modify to format specific cells.  Just as a couple of examples,  how would I, say set Cell C4 to the string value "Hello World" and have it centered?  And how would I set, say cells B10 thru G10 to the RGB color value 200, 200, 200?

Finally, my macro currently runs a routine on every worksheet in my workbook.  However, I'd like to have it skip "Sheet1" as Sheet1 is of a totally different format and I don't want the macro run against is.  My macro currently reads:

For Each sht In ActiveWorkbook.Worksheets

How do I modify it to something like:

For Each sht In ActiveWorkbook.Worksheets EXCEPT SHEET1

Question by:dbfromnewjersey
LVL 13

Accepted Solution

Shanan212 earned 2000 total points
ID: 38418028
Inside your For statement

That is

For Each sht In ActiveWorkbook.Worksheets
if sht.name <> "Sheet1" then
next sht

in the above way, it only go through your statements if the sheet name is not "Sheet1"

To set string in C4

    ActiveCell.FormulaR1C1 = "Hello World"
    Selection.HorizontalAlignment = xlCenter

Open in new window

To set color

    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 13158600
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With

Open in new window


Author Comment

ID: 38419129
Thank you.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

805 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question