+ Reply to Thread
Results 1 to 9 of 9

how to compare two cells in different colums

  1. #1
    Registered User
    Join Date
    01-18-2011
    Location
    Dubai
    MS-Off Ver
    Excel 2007
    Posts
    7

    how to compare two cells in different colums

    Hi mates
    Please How can I write the code for comparing two cells in different coloums in VBA.

    like A1 has a value of 40 , B1 has a value of 50
    I want a code to say
    if the value of A1 grater than value of b1 do so and so.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: how to compare two cells in different colums

    Maybe something like this:
    Please Login or Register  to view this content.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    01-18-2011
    Location
    Dubai
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: how to compare two cells in different colums

    ok but how if I want all bs to be in the same format not only b1
    like b2 ,b3 b4 I'll compare them with A1 a2 a 3 a4 and so on

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: how to compare two cells in different colums

    Maybe if you could attach a mock workbook with a description of exactly what you want done we can be of more assistance. You could use a loop to loop the cells but a loop needs an ending point for which "and so on" does not provide.

  5. #5
    Registered User
    Join Date
    01-18-2011
    Location
    Dubai
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: how to compare two cells in different colums

    i put this code
    Private Sub Worksheet_Change(ByVal Target As Range)



    If Range("A1").Value > Range("B1").Value Then
    Target.EntireRow.Interior.ColorIndex = 7

    End If



    End Sub


    the problem wherever i put a nu,ber in the sheet the entire row turned pink how to solve it

  6. #6
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: how to compare two cells in different colums

    You have to use code tags when using VBA code in this forum. Please refer to rule #3 to see how to apply them. I cannot help you until you do.

  7. #7
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: how to compare two cells in different colums

    Someone else may have to step in on this as I have to go to class in a couple of minutes.

  8. #8
    Registered User
    Join Date
    01-18-2011
    Location
    Dubai
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: how to compare two cells in different colums

    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,697

    Re: how to compare two cells in different colums

    Please Login or Register  to view this content.
    Compares cells in column B to cells in column A, starting at A2, in the same row.
    It will mark the cells in column B if that cell has a different value than the value of the cell in column A

    Regards
    John

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1