+ Reply to Thread
Results 1 to 3 of 3

Comparing Content of 2 Cells in VBA

  1. #1
    Registered User
    Join Date
    09-26-2007
    Posts
    32

    Comparing Content of 2 Cells in VBA

    I have a spreadsheet sorted by name with a variety of amounts of entries by different name:

    A B
    name 1 £1
    name 1 £3
    name 1 £5
    name 1 £2
    name 2 £23
    name 2 £21

    I have a counter to total up the amounts by each name - and the method I want to use is:

    Activate a1 then add b1 to counter
    Activate a2

    Here I need to check if the cell is different from the previous one so I can export the total to another sheet.

    I want to use an If statement so if a2 IS different I can export the counter however if it is the same add the content of B2 to the counter and go onto the next one.

    The code I have tried is:

    Please Login or Register  to view this content.
    ------------------------------------------

    The last line is the check I am using however, it doesn't matter what is in the previous cell it never goes back to loop1.

    How can I get the condition to work?

    There are a number of reasons why I want to do it this way, but it would take me too long to explain.

    To clarify, I just need to compare A2 with A1 to see if it is the same. If it is it goes back to loop1 (as above) otherwise carries on the code after.

    Thanks

    Kev
    Last edited by VBA Noob; 09-01-2008 at 08:59 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Kev,

    Here is a macro that doesn't require the cell be selected and uses "A1" reference style. This will start at row 1 of column "A" on the active sheet and continue until the first blank cell is found. The name and the total are transfered over to "Sheet2" starting in cell "A1".
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    09-26-2007
    Posts
    32
    Hi Leith

    I stepped through the routine - but it doesn't seem to output anything into sheet2.

    Have I or you missed something?

    Oh sorry I should also say that'll need it to start at A2 because of a header. I assume I make R to equal 2 initially?

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 07-14-2008, 03:24 PM
  2. Comparing multiple cells
    By Yidog21 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-21-2007, 05:04 PM
  3. Access cell's content via Concatenate
    By aduroche in forum Excel General
    Replies: 4
    Last Post: 06-11-2007, 07:37 AM
  4. Problem Linking Cells in Different Workbooks
    By jeffc4442 in forum Excel General
    Replies: 7
    Last Post: 02-23-2007, 11:01 AM
  5. Combining content from to cells into a string
    By rgarcia.banler in forum Excel General
    Replies: 5
    Last Post: 02-01-2007, 06:45 PM

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