Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Automatically Format Range of Cells

Steve,

How do I incorporate this code, written below, into my spreadsheet? I have
never actually input code such as that into a spreadsheet before. Do you
just type it into the cell, or is there a different procedure for this?
Thanks.

"Steve Yandl" wrote:

Nigel,

See if something like this subroutine will do what you want.

Sub Decorate()
Dim rngB As Range
Dim rngTemp As Range
Set rngB = Sheets(1).UsedRange.Columns("B:B")
For R = 1 To rngB.Rows.Count
If Sheets(1).Cells(R, 2).Value = "Category" Then
Set rngTemp = Sheets(1).Cells(R, 2).Range("A1:O1")
rngTemp.Font.Bold = True
With rngTemp.Interior
..ColorIndex = 41
..Pattern = xlSolid
..PatternColorIndex = xlAutomatic
End With
End If
Next R
End Sub


Steve
"Nigel" wrote in message
...

Thanks, but this does not work for what I want, the word category could be
in any row (although it will only be in Column B), plus I want the row
where
the word category to get the new formating, so the first time I run it the
word could be in rows 2,17 and 23. The next time I run it the word could
be
in 4,6,9,14,23 etc.

I need to do a find of the word category and then format columns B to P
for
that row


"Leith Ross" wrote:


Hello Nigel,

You can make those changes automatically by using Conditional
Formatting. Select the Range of cells you want and go to Format on the
Menu and select *Conditional Formatting...* You can implement upto 3
conditional formats.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile:
http://www.excelforum.com/member.php...o&userid=18465
View this thread:
http://www.excelforum.com/showthread...hreadid=490440





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 284
Default Automatically Format Range of Cells

Just hold down the Alt key and press F8. Type the word "Decorate" for a
subroutine name and the click the 'Create' button. You can paste the
routine below over the sub and End sub lines that Excel will create for you
or simply type the guts of the routine between the two lines (don't
duplicate the sub and end sub lines is all).

You may want to take a look at the comments Gord posted regarding
Conditional Formatting. The only advantage to the subroutine I show over CF
is that it will determine the range without you having to guess the max
number of rows you might have. On the other hand, I didn't write anything
to clear formatting in the case where you run the routine a second time with
different values in column B (that could be done however).

To run the subroutine, just do Alt plus F8, pick the sub you want to run and
click the "run" button. Many people prefer to attach the subroutine to a
new tool button or use some event to trigger the action but I find it pretty
simple to do Alt + F8 most of the time if I'm the primary user.

Steve


"Gee-off" wrote in message
...
Steve,

How do I incorporate this code, written below, into my spreadsheet? I
have
never actually input code such as that into a spreadsheet before. Do you
just type it into the cell, or is there a different procedure for this?
Thanks.

"Steve Yandl" wrote:

Nigel,

See if something like this subroutine will do what you want.

Sub Decorate()
Dim rngB As Range
Dim rngTemp As Range
Set rngB = Sheets(1).UsedRange.Columns("B:B")
For R = 1 To rngB.Rows.Count
If Sheets(1).Cells(R, 2).Value = "Category" Then
Set rngTemp = Sheets(1).Cells(R, 2).Range("A1:O1")
rngTemp.Font.Bold = True
With rngTemp.Interior
..ColorIndex = 41
..Pattern = xlSolid
..PatternColorIndex = xlAutomatic
End With
End If
Next R
End Sub


Steve
"Nigel" wrote in message
...

Thanks, but this does not work for what I want, the word category could
be
in any row (although it will only be in Column B), plus I want the row
where
the word category to get the new formating, so the first time I run it
the
word could be in rows 2,17 and 23. The next time I run it the word
could
be
in 4,6,9,14,23 etc.

I need to do a find of the word category and then format columns B to P
for
that row


"Leith Ross" wrote:


Hello Nigel,

You can make those changes automatically by using Conditional
Formatting. Select the Range of cells you want and go to Format on the
Menu and select *Conditional Formatting...* You can implement upto 3
conditional formats.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile:
http://www.excelforum.com/member.php...o&userid=18465
View this thread:
http://www.excelforum.com/showthread...hreadid=490440







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically format charts with range of dates Sean Moor Charts and Charting in Excel 13 June 17th 08 02:24 PM
How to run macro automatically from range of cells Kevin Excel Worksheet Functions 6 October 19th 07 01:45 AM
automatically fill in a range of cells Maarten Excel Discussion (Misc queries) 1 April 29th 05 11:14 AM
numbers in cells are automatically divided by 100. Not a format s. Surveyor Excel Worksheet Functions 1 February 22nd 05 04:30 PM
Can i automatically format cells to be a certain color if the val. jack442 Excel Worksheet Functions 2 October 28th 04 05:31 PM


All times are GMT +1. The time now is 11:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"