+ Reply to Thread
Results 1 to 7 of 7

VBA macro, move cell contents, duplicate down if additional value, delete empty rows

  1. #1
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61

    Lightbulb VBA macro, move cell contents, duplicate down if additional value, delete empty rows

    Hello,

    I have the following formula built that moves the cell content but I have the following issues I can not seem to solve. In the form below I am trying to move the contents from column "B" to Column"A" if the value begins with "100". This I was able to accomplish with the following macro. The issue I am having is that I need the data to move over one column and down one row to where the contents of cell B has a value. Further more IF the contents of "B" has multiple cells with a value the data that was moved to "A" needs to be duplicated down. I also need to delete the first column that has a qty "D" but the item "B" is null. Not all rows will have an additional item and some rows will have more than two items. This is unpredictable.

    What it looks like now when the current Macro is run:

    A B C D
    PO Item Description Qty
    1000022
    184D1822P001 Green 6
    184D1822P001 BIG 10
    16


    1000070
    184D1387P004 840
    840


    Please Login or Register  to view this content.
    Please let me know if there is anything I can do to clarify further and thank you for your help. I have tried researching and looking everywhere.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA macro, move cell contents, duplicate down if additional value, delete empty rows

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61
    Please see attachment
    Attached Files Attached Files

  4. #4
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: VBA macro, move cell contents, duplicate down if additional value, delete empty rows

    Hi lengwer,
    . This sort of problem is technically very simple but just requires a lot of careful looping to rearrange to the order in which you want the output.
    . Here is a start. It basically does what it appears you want from the info you gave. Note however I am using a VBA Array approach in this example. It is a quick, favoured method but it does not maintain formatting.
    . To preserve Formatting you would need to use a slower spreadsheet interaction method. But the basic idea / looping would be the same. Try this for now and when you feedback we can take it from there if you want it done differently. ( I have, for this example, arranged that the output goes to a newly made sheet with the name “Output” )
    ........
    .. So, my code takes this:

    Using Excel 2007
    -
    A
    B
    C
    D
    E
    F
    G
    H
    I
    1
    Sales Order Comparison Exceptions
    2
    Run Date: 08/06/2015
    3
    Original Order Q’ty
    Remaining Balance Due
    4
    Line # Item Description Per Deb Per G Variance Per Deb Per G Variance
    5
    6
    Order #
    1000022
    7
    1
    164B1822G001
    0
    480
    (480)
    0
    480
    (480)
    8
    1
    123A1822H001
    2520
    480
    2040
    0
    480
    (480)
    9
    Order Totals
    2520
    960
    1560
    0
    960
    (960)
    10
    11
    Order #
    1000070
    12
    1
    1H4Y1387J004 ROD ANODE-50G
    0
    840
    (840)
    0
    (40)
    40
    13
    Order Totals
    0
    840
    (840)
    0
    (40)
    40
    14
    15
    Order #
    1000139
    16
    1
    194J1734K002 BLADE FAN
    0
    1000
    (1000)
    0
    (100)
    100
    17
    Order Totals
    0
    1000
    (1000)
    0
    (100)
    100
    Before


    And working on that makes a new sheet called “Output” that then looks like this:

    Using Excel 2007
    -
    A
    B
    C
    D
    E
    F
    G
    H
    I
    1
    PO# Item Description Per Deb PerG Variance Per Deb Per G Variance
    2
    1000022 164B1822G001 0 480 -480 0 480 -480
    3
    1000022 123A1822H001 2520 480 2040 0 480 -480
    4
    1000070 1H4Y1387J004 ROD ANODE-50G 0 840 -840 0 -40 40
    5
    1000139 194J1734K002 BLADE FAN 0 1000 -1000 0 -100 100
    Output


    .....


    Code in next post Post #5

    Alan.
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

  5. #5
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: VBA macro, move cell contents, duplicate down if additional value, delete empty rows

    Code for post #4

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61

    Re: VBA macro, move cell contents, duplicate down if additional value, delete empty rows

    This works exactly as I needed. I went through a longer process. I had three separate command buttons and each preformed an action to set the file up as needed. The way you have the code written I can use just one command button and it is completed on a separate tab. Thank you!!

    Below is how I had mine written:

    Please Login or Register  to view this content.

  7. #7
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: VBA macro, move cell contents, duplicate down if additional value, delete empty rows

    Hi

    Quote Originally Posted by lengwer View Post
    This works exactly as I needed. ...... The way you have the code written I can use just one command button and it is completed on a separate tab. Thank you!!

    ....
    . Yous welcome, thanks for the feedback

    Quote Originally Posted by lengwer View Post
    .... I went through a longer process. I had three separate command buttons and each preformed an action to set the file up as needed. ......

    Below is how I had mine written:

    ....
    . Thanks for feeding back and sharing. It is always good to see alternative solutions to the same problem.

    Alan

+ 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. Delete empty rows and duplicate entries
    By zxchan in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-05-2014, 03:41 PM
  2. [SOLVED] Move data on duplicate rows (different columns) to one row and delete extra rows?
    By Sagwa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-01-2014, 08:25 AM
  3. Macro to delete several rows based on a cell's contents
    By ppp112 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-26-2013, 01:16 PM
  4. [SOLVED] Move Contents of Cells and Eliminate Empty Rows
    By aviatecar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2012, 08:44 PM
  5. delete duplicate rows, delete empty rows
    By loade in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-03-2012, 05:42 AM
  6. Macro to move cell contents of multiple rows into one if criteria is met
    By citygov in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2012, 05:32 PM
  7. Replies: 2
    Last Post: 08-24-2011, 05:42 PM

Tags for this Thread

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