+ Reply to Thread
Results 1 to 16 of 16

Cell not equal to previous cell?

  1. #1
    Registered User
    Join Date
    09-29-2011
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    29

    Question Cell not equal to previous cell?

    Please Login or Register  to view this content.
    My current and INCOMPLETE code is posted. I am new to VBA and what I am doing should be simple but I am apparently not using the correct syntax. I want to go through a list and every time the number in the cell I am currently in (my active cell) is not equal to the number in the same column in the row before it I want to add 2 rows afterwards. Otherwise I want to check the next row down and see if it is equal to the row before it.

    In non vba is should look something like this:

    Select Cell B2

    Until empty
    if Active Cell DOES NOT EQUAL Previous Cell (up one row, no column offset)
    insert 2 rows
    then select the cell 2 rows down, no column offset
    else select the next Cell (down one row, no column offset)
    end the loop

    Let me know if this doesn't make sense
    Last edited by sweedey; 09-29-2011 at 08:25 PM. Reason: Added code tags

  2. #2
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Active Cell Not Equal to Previous Cell

    Your post did not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    I've added the tags for you in this post; please use them in the future.
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

  3. #3
    Registered User
    Join Date
    09-29-2011
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    29

    Re: HELP: how to say cell not equal to previous cell?

    Sorry about that, I saw that we needed to do that, but couldn't find how because I was in a hurry! Thanks for the assistance!

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: HELP: how to say cell not equal to previous cell?

    Maybe try this:

    Please Login or Register  to view this content.
    abousetta
    Last edited by abousetta; 09-29-2011 at 08:21 PM.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: HELP: how to say cell not equal to previous cell?

    ConneXionLost has your avatar's teeth gotten sharper or is my screen resolution all of a sudden much better

  6. #6
    Registered User
    Join Date
    09-29-2011
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    29

    Red face Re: Cell not equal to previous cell?

    Thanks! That is SOO close to what I want it to do, unfortunately I do not exactly understand it or I would fiddle with it to get it to work. I want the insertion of rows to happen between the different numbers rather than the same numbers

    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Cell not equal to previous cell?

    My bad... I misread the intention. Just change the equal sign to not equal (e.g. <>). I have done this in the code that I posted earlier. It seems to work on my sample.

    abousetta

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Cell not equal to previous cell?

    If you are interested in how the code works, I can provide detailed explanation later tonight (or over the weekend).

    abousetta

  9. #9
    Registered User
    Join Date
    09-29-2011
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    29

    Re: Cell not equal to previous cell?

    thank you SO much! You are a life saver!

  10. #10
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Cell not equal to previous cell?

    Just spreading the love ... My @ss has been on the line more than once and others have chipped in to save it...

    Good luck.

    abousetta

    P.S. If you are satisfied with the answers, please mark the thread as solved. Also reputation points (scales) are always welcomed. In fact I have over 800 posts... feel free to add rep points to any of them
    Last edited by abousetta; 09-29-2011 at 08:29 PM.

  11. #11
    Registered User
    Join Date
    09-29-2011
    Location
    Georgia
    MS-Off Ver
    Excel 2007
    Posts
    29

    Re: Cell not equal to previous cell?

    if you have time at some point that would be great! I am really trying to learn this stuff, but it seems like when I start grasping something the way to actually do it is completely different than what I thought!

    Oh - and how do I do the reputation point thing - I am very new to this forum

  12. #12
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Cell not equal to previous cell?

    There are many ways to do the same thing. The more proficient you become with vba, you will begin to recognize how to consolidate the code and make it more efficient. I will do my best to post a detailed description over the next few days.

    Good luck.

    abousetta

  13. #13
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Cell not equal to previous cell?

    If you like a post then you can click on the scales (upper right corner of the post). Then if will ask you if you approve or disaprove of the post.

    abousetta

  14. #14
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: HELP: how to say cell not equal to previous cell?

    Quote Originally Posted by abousetta View Post
    ConneXionLost has your avatar's teeth gotten sharper or is my screen resolution all of a sudden much better
    Only if you`ve bought a new monitor. And no, I`m not going to quote the Big Bad Wolf here.

  15. #15
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Cell not equal to previous cell?

    Same monitor(s) but I did switch to Child 3.7 which seems to have lower graphics, but allows me to use color in the code. And then all of a sudden I could have sworn that your avatar was looking at me funny ...

    I quess enough forums for today and more real work.

    abousetta

  16. #16
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Cell not equal to previous cell?

    As promised, let's break this code down to see its components:

    Declare variables to speed up the code. Put the ones used most often on the top and so forth.
    Please Login or Register  to view this content.
    Get the row number of the last used cell in column B
    Please Login or Register  to view this content.
    Starting from the bottom and working your way up, one row at time (that's the Step -1). x is will converted to a number (e.g. 200, 199, 198, etc. until we reach 2)
    Please Login or Register  to view this content.
    Equation: Using the cells approach to determine the cell, if the cell in Column B is not the same as the cell above it, then add two rows
    Please Login or Register  to view this content.
    Next row (up)
    Please Login or Register  to view this content.
    Hope this helps.

    abousetta (signing off for the day)

+ 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