+ Reply to Thread
Results 1 to 7 of 7

Inserting a row above if the value is different

  1. #1
    Registered User
    Join Date
    01-15-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2013
    Posts
    95

    Inserting a row above if the value is different

    Hello,

    I'm trying to figure out how to insert a row above when the value in a cell is different from the one above it. I'm pretty sure I have to loop it but I'm still very new to VBA so any help would be greatly appreciated.

    Here's what I have so far.. but I keep getting an error when I'm trying to find the last row. Same_Name.xlsm


    Thanks in advance.
    Last edited by GreenTee; 03-09-2015 at 04:12 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: Inserting a row above if the value is different

    looks like you forgot to set ws in this sub

    Set ws = Sheets("Sheet1")
    Hope I could help - if your post has been solved don't forget to mark it as such.

    Clicking the * below is a great way to say thanks!

    "Drowning in 10 feet of water isn?t any different than drowning in a million feet. And if you can swim, it doesn?t matter how deep the ocean is. At some level, once you realize you?re in water that?s too deep to stand, you have to have a very different approach," - Joi Ito

  3. #3
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: Inserting a row above if the value is different

    also your cells() reference below should be looking at column 2 instead of column 0.

    this appears to be working - inserting a row below the first instance of a new name, although I'm not real clear on what you're trying to accomplish by inserting these rows... guess you feel comfortable w/ whatever the next segment of code is supposed to do?

    Please Login or Register  to view this content.

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Inserting a row above if the value is different

    No, post deleted as I did somthing wrong when testing and compairing results!


    Alf
    Last edited by Alf; 03-09-2015 at 03:03 PM. Reason: Comment not right

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Inserting a row above if the value is different

    Try this code
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-15-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2013
    Posts
    95

    Re: Inserting a row above if the value is different

    Quote Originally Posted by simarui View Post
    also your cells() reference below should be looking at column 2 instead of column 0.

    this appears to be working - inserting a row below the first instance of a new name, although I'm not real clear on what you're trying to accomplish by inserting these rows... guess you feel comfortable w/ whatever the next segment of code is supposed to do?

    Please Login or Register  to view this content.


    Ahh.. thanks Simarui! this solved my problem... and apologies for making it so vague. I do have some other code that runs before and after it but just wanted to keep the forum simple since this was the part that's giving me an issue.

  7. #7
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: Inserting a row above if the value is different

    glad i could help, don't forget to mark the thread as solved!

+ 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: 0
    Last Post: 05-20-2014, 11:58 AM
  2. Replies: 6
    Last Post: 08-29-2010, 08:15 AM
  3. inserting cells into a hyperlink, inserting link via macro
    By jackmc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-17-2007, 12:02 AM
  4. [SOLVED] Inserting row
    By umba-sr in forum Excel General
    Replies: 3
    Last Post: 04-13-2006, 11:00 AM
  5. inserting a row
    By erin m in forum Excel General
    Replies: 1
    Last Post: 01-13-2005, 02:06 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