+ Reply to Thread
Results 1 to 2 of 2

VBA Code inserting rows and doing calculations where it shouldn't.

  1. #1
    Registered User
    Join Date
    04-05-2012
    Location
    Southfield, Michigan
    MS-Off Ver
    Excel 2003
    Posts
    63

    VBA Code inserting rows and doing calculations where it shouldn't.

    Hello,

    I have a snippet of code here that should do the following:

    1) Place a simple "IF" formula in Row X of Column B. The IF formula does the following:

    -Compares value in Row x of Column D to value of Row x+1 of Column D (So D4 and D5 for example)
    -If values are the same, leave row in Column B blank or empty
    -If values are different put a "1" in Row X of Column B.

    (so, if D5 was different than D4, cell B4 would get a "1")

    2) For every row where there is a "1", the Macro should

    -Insert a row beneath the row containing the "1"

    Example: "WHAT IT SHOULD DO..."

    BEFORE:

    D4 Apples
    D5 Oranges
    D6 Oranges
    D7 Bananas
    D8 Grapes
    D9 Cherries

    AFTER:

    D4 Apples
    D5
    D6 Oranges
    D7 Oranges
    D8
    D9 Bananas
    D10
    D11 Grapes
    D12
    D13 Cherries

    Now, for some reason, the macro only does the very first run through correctly, but after that, it does almost the COMPLETE OPPOSITE of what it should do.

    It inserts blank rows underneath one another over and over and then it only sporadically inserts a blank row between the values in Column D that are different from the value in the row above it, missing multiple different values in the process.

    Example: "WHAT IT IS DOING..."

    BEFORE:

    D4 Apples
    D5 Oranges
    D6 Oranges
    D7 Bananas

    AFTER:

    D4 Apples:
    D5
    D7 Oranges
    D8 Oranges
    D9
    D10
    D11
    D14 Bananas
    D15 Grapes
    D16 Cherries

    Please Login or Register  to view this content.
    Really could use some help with this one please.

    Thanks,

    R.J.
    Last edited by rjw524; 03-02-2015 at 01:41 PM.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,942

    Re: VBA Code inserting rows and doing calculations where it shouldn't.

    When you are inserting rows, it is better to start at the bottom and go up. And you need to have a check for all your conditions, including the blanks. Try this:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

+ 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. Code exits Function at a point where it shouldn't be possible to exit
    By 6StringJazzer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-22-2014, 03:39 AM
  2. [SOLVED] Code for conditionally inserting rows
    By bfleming in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-14-2013, 12:35 PM
  3. [SOLVED] Loop Code skips rows eventhough it shouldn't
    By questionguy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-13-2012, 08:58 AM
  4. VBA Code shouldn't export header information
    By Magerator in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2010, 08:52 AM
  5. Inserting new rows VBA code
    By CityMPLSEmpolyee in forum Excel General
    Replies: 8
    Last Post: 10-05-2010, 12:07 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