Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

formatting cell colour columns

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Formatting Cell colour of columns

Formatting Cell colour of columns

ResolvedVersion 2003

Sarah has attended:
Excel VBA Intro Intermediate course
Access Advanced course
Access Intermediate course

Formatting Cell colour of columns

This is my code I've got which works but needs altering.

Sub colorvalue()

Dim MyCell
For Each MyCell In Range("bacon").Cells
If IsNumeric(MyCell) And MyCell <> "" Then
Select Case MyCell
Case Is < 13
MyCell.Interior.ColorIndex = 10
Case Is < 26
MyCell.Interior.ColorIndex = 4
Case Is < 38
MyCell.Interior.ColorIndex = 43
Case Is < 51
MyCell.Interior.ColorIndex = 6
Case Is < 63
MyCell.Interior.ColorIndex = 44
Case Is < 76
MyCell.Interior.ColorIndex = 45
Case Is < 88
MyCell.Interior.ColorIndex = 46
Case Is < 101
MyCell.Interior.ColorIndex = 3
End Select
End If
Next MyCell


End Sub


Basically this macro has worked on one sheet where I've called the whole of column F "bacon".

The thing is I have another 54 spreadsheets all laid out exactly the same way and I want to run the macro on each sheet.

I can't call all column F's bacon as for each sheet it wants a different name.

so how do I write in the code that on the sheet that I've got active at that time, to run this macro on the whole of column F? Without having to name any data ranges.

Sarah

Edited on Mon 12 Apr 2010, 09:17

RE: Formatting Cell colour of columns

Hi Sarah

Thanks for your question

I suggest creating a range object and then setting that equal to column F in the active sheet

For example

 Dim rngRange as range

set rnnRange = activesheet.columns("F")


For each MyCell in rngRange.cells


And then carry on as before.

If you have problems let me know and we can try something else

Regards

Stephen

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Conditional Formatting in Excel 2010

If you have lots of data in a spreadsheet, you may find that it is easier to read if you highlight some of the values. This is Conditional Formatting and here's how to use it:

1) Select the data you wish to apply the format to and click Conditional Formatting
2) A list of options will then appear, from this list, choose the format you wish to display e.g. find all cells with a value less than 0
3) Excel will then highlight all of these cells

To remove this: select the highlighted cells, click the drop down on the Conditional Formatting icon and select Clear Rules from selected cells.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.