ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Searching with Macros (https://www.excelbanter.com/excel-programming/303955-searching-macros.html)

Kura of Tyren

Searching with Macros
 
Does anyone know how I can make a macro that will search
all cells within a preset range and change the font color
of all cells with a value of less than 20 to red while
leaving all other cells in the region with their normal
color?

Frank Kabel

Searching with Macros
 
Hi
why not use Conditional Format for this?. Simply select your data range
and goto 'Format - Conditional Format' for this

--
Regards
Frank Kabel
Frankfurt, Germany


Kura of Tyren wrote:
Does anyone know how I can make a macro that will search
all cells within a preset range and change the font color
of all cells with a value of less than 20 to red while
leaving all other cells in the region with their normal
color?



Don Guillett[_4_]

Searching with Macros
 
something like this

for each c in selection 'or range("a2:x234")
if c<20 then c.interior.colorindex=34 'change number to suit
next

--
Don Guillett
SalesAid Software

"Kura of Tyren" wrote in message
...
Does anyone know how I can make a macro that will search
all cells within a preset range and change the font color
of all cells with a value of less than 20 to red while
leaving all other cells in the region with their normal
color?




No Name

Searching with Macros
 

-----Original Message-----
Does anyone know how I can make a macro that will search
all cells within a preset range and change the font

color
of all cells with a value of less than 20 to red while
leaving all other cells in the region with their normal
color?
.


This should work!

Sub FillCell()

'sets start area to check, in this example 1,1 or A1
startrow = 1
startcolumn = 1

'sets end of area to check, in this example 3,14 or c14
endcolumn = 3
endrow = 14

For x = startrow To endrow
For y = startcolumn To endcolumn
If Cells(x, y).Value < 20 Then
'sets colour to red
Cells(x, y).Interior.ColorIndex = 3
Else
'clears format
Cells(x, y).Interior.ColorIndex = xlNone
End If
Next y
Next x

End Sub

Don Guillett[_4_]

Searching with Macros
 
TESTED
Sub colorem()
Range("a2:x234").Cells.Interior.ColorIndex = 0
For Each c In Range("a2:x234")
If c < "" And c < 20 Then c.Interior.ColorIndex = 3
Next
End Sub
--
Don Guillett
SalesAid Software

"Don Guillett" wrote in message
...
something like this

for each c in selection 'or range("a2:x234")
if c<20 then c.interior.colorindex=34 'change number to suit
next

--
Don Guillett
SalesAid Software

"Kura of Tyren" wrote in message
...
Does anyone know how I can make a macro that will search
all cells within a preset range and change the font color
of all cells with a value of less than 20 to red while
leaving all other cells in the region with their normal
color?







All times are GMT +1. The time now is 01:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com