Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Excel Question (or visual basic)
Closed Thread
Old 02-10-2005, 07:50 AM   #1 (permalink)
 
All Seeing Eye

Join Date: Apr 2002

Posts: 72

azury

Default Excel Question (or visual basic)

Hey there. I've just started to understand how macros work on excel. I've done a workbook containing a weekly-upadated information. Every week another line of information is added to the workbook.
I want to make a simple thing like this: I want the macro to check every cell on the chosed line. if the cell is equal to the cell above him, it will be remain with "no fill". if the cell is greater than the cell above him, it will be painted with green. and if he is less, it will be painted in red. no a hard task, though I'm not sure how to create this macro.
I also understand that something like this can be created using "condicional formatting" option, though I couldn't find a quick way to apply it on many cells, only on one (and that's not helpful enough).

thanks alot for any help given..
azury is offline  
Old 02-12-2005, 10:46 AM   #2 (permalink)
 
Ultra Techie

Join Date: Sep 2003

Location: Bamberg, Germany

Posts: 549

Iron_Cross

Send a message via ICQ to Iron_Cross Send a message via MSN to Iron_Cross Send a message via Yahoo to Iron_Cross
Default

I've never made macros, so I'll just give you the jist of what needs to be done. You'd need two variables to hold two cells, then you might need two variables for colors, but you might not. The structure would look someting like this:

Code:
cRed    <---- that is the color red as a variable
cGreen <---- That is the color green as a variable

oldCell     <---- That is the first cell variable
currCell    <---- this is the second variable and it's the current working cell

for ( <find a way to loop through all the cells in the table> )
    oldCell = currCell <set the last current cell equal to the old cell>
    currCell = <set the next cell in the line equal to the current cell>
    if( oldCell <> Nothing ) Then
        <here we check to make sure oldCell actually equals something, if not then it's the first cell>
        if( currCell = oldCell ) Then
             <skip this section because nothing needs to be done if they match>
       else if (currCell > oldCell ) Then
             currCell.Color = cGreen
       else 
             <the current cell must be less than if it's not equal to or greater than>
             currCell.Color = cRed
       endif
   endif
endloop
Now this is not actual code, it's just to show you what you'd need to do....It's not even actual VB it's just partly vb
But you should get the idea of what needs to be done now.
__________________

See today\'s Penny-Arcade!(May contain foul lanuage)
Pain is weakness leaving the body.

PM Me for my MSN
Iron_Cross is offline  
 
Closed Thread

Thread Tools
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