If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > simlple excel macro

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-25-04, 04:28
yaron yaron is offline
Registered User
 
Join Date: Mar 2004
Posts: 1
simlple excel macro

Hello all,

I want to build a macro in excel that will scan the unempty cells and color them accordingly.
e.g. if a cell contains the word 'hello' it will color it yellow etc.

any ideas?
Reply With Quote
  #2 (permalink)  
Old 03-25-04, 09:31
shades shades is offline
Registered User
 
Join Date: Oct 2003
Posts: 1,091
Try this:

Code:
Sub ColorCell()

Selection.SpecialCells(xlCellTypeConstants, 23).Select
    With Selection.Interior
        .ColorIndex = 36
        .Pattern = xlSolid
    End With
End Sub
Change color index as needed.
__________________
old, slow, and confused
but at least I'm inconsistent!

Rich
(retired Excel 2003 user, 3/28/2008)

How to ask a question on forums
Reply With Quote
  #3 (permalink)  
Old 03-25-04, 12:08
Smitty Smitty is offline
Registered User
 
Join Date: Dec 2003
Location: San Diego, CA
Posts: 153
Welcome to the Board!

You could also use Conditional Formatting-->Cell Value Is-->Equal To-->="Hello" Then Format-->Patterns-->Yellow.

Hope that helps,

Smitty
Reply With Quote
  #4 (permalink)  
Old 04-09-04, 10:36
fesoy fesoy is offline
Registered User
 
Join Date: Apr 2004
Posts: 1
Question Hiding rows

Hello all

I am new to macros in excel. I have a column that is currently empty but will be inputted with dates soon.

What i want to do is have two macros: one will go through the entire spreadsheet and select the rows that have a date in the aforementioned column cell AND hide that particular row. The other will do the opposite - it will unhide the rows that were previously hidden.

please help

y
Reply With Quote
  #5 (permalink)  
Old 04-09-04, 10:57
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
Re: Hiding rows

ok

Here are 2 macros for you

Code:
Sub Macro1()
'hides rows that contain numbers
    Range("A1").EntireColumn.SpecialCells(xlCellTypeConstants, xlNumbers).EntireRow.Hidden = True
End Sub

Sub Macro2()
'unhides all rows
    Cells.EntireRow.Hidden = False
End Sub
Macro1 hides all rows containing numbers
as Excel interprits dates as numbers then these rows will be hidden
it looks for numbers in column A

HTH

David

macro2 unhides all hidden rows on the worksheet
Reply With Quote
  #6 (permalink)  
Old 04-09-04, 11:17
SR22Mike SR22Mike is offline
Registered User
 
Join Date: Mar 2004
Location: Minnesota, USA, Earth
Posts: 65
Select Case

Yaron,

You can also try Select Case in VBA. Something like...
sub ColorCells()
Do
Select Case ActiveCell.Value
Case "Hello"
'using shades code.
Selection.SpecialCells(xlCellTypeConstants, 23).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Case ""
'Do Nothing or hide.
Case "Good-Bye"
'Do somthing else.
Case Else
'Catch everything else...do something...do nothing.
End Select
ActiveCell.offset(1,0).select
Loop Until (some end condition)
End Sub
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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