Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cell compare Excel macro

Status
Not open for further replies.

JustATheory

IS-IT--Management
Feb 27, 2003
115
US
Greetings,

I have a pretty good understanding of the ActiveCell = function. But I'm having trouble with comparing values in two cells. For instance, I would like the cursor to look at the value in cell B1, then compare it to the value in B2, if they are the same, move to B3, if they differ then perform an action. Any help is greatly appreciated.

Thanks,
Andy
 
Have a look at Offset

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
and please try and move on from using Activecell as it causes all sorts of issues with code - it is nearly always better to reference a cell/range directly

Rather than using
Code:
Range("A1").select
Selection.DoStuff
or
Code:
Range("A1").Activate
Activecell.DoStuff
you should use
Code:
Range("A1").DoStuff

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 


Your snippit of an example may answer this extremely focused question, but I have a feeling, that you are looping thru a range and comparing values based on the position in the loop.

Guessing...
Code:
for lRow = 2 to 9 Step 2
  with cells(lRow, "B")
    if .value <> .offset(1, 0).value then 'the first occurrence compares B2 to B3
       'do something
    end if
  end with
next


Skip,

[glasses] [red]Be Advised![/red] A chicken, who would drag a wagon across the road for 2 cents, is…
POULTRY in motion to PULLET for a PALTRY amount! [tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top