+ Reply to Thread
Results 1 to 18 of 18

Macro to insert # of row specific in a cell

  1. #1
    Registered User
    Join Date
    05-06-2011
    Location
    New York, US
    MS-Off Ver
    Excel 2007
    Posts
    25

    Smile Macro to insert # of row specific in a cell

    Hi All,

    hope someone can help to achieve the below.
    I am working on an excel file as attached file, tiger.xls
    this is what i am trying to accomplish to write in Marco.

    Part A:
    in the H column, i need to insert the # of row minus the number that is in the cell. for ex. when
    H2 = 3, to insert 2 blank row down
    H3 = 2, to insert 1 blank row down

    however, if the cell is 1, then do not add any row

    Inserting the blank row should come to a STOP whenit reaches [Total] on colunm A.
    when this is done, the file shouuld like file as attached: lion.xls

    Part B:
    Auto populate the number in an increasement format in the empty cells follow by the Max# in Column A.

    in this example, in Colunm A the max# is 10. so
    the first empty cell [A3]l should be listed as 11.
    The increasment should be carried on, unitl it reaches a smaller number.
    in this case:

    A3 = 11
    A4 = 12
    A5 = 2

    stop, and then

    A6 = continue to auto populate [increasement] from last Max #
    which means, A6 = 13

    auto populate number should be stopped when it reaches to the cell [Total]

    the final file should look like as attached, bear.xls

    Appreciate for any thoughts and comment.

    Regards
    Attached Files Attached Files
    Last edited by NBVC; 05-10-2011 at 02:20 PM. Reason: Sloved

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,510

    Re: Marco insert # of row specific in a cell

    For the first part:

    Please Login or Register  to view this content.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Marco insert # of row specific in a cell

    Try this with your Sheet "Tiger"
    Please Login or Register  to view this content.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  4. #4
    Registered User
    Join Date
    05-06-2011
    Location
    New York, US
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Marco insert # of row specific in a cell

    TMShucks and Marcol, it works perfectly! you guys are awesome! thanks.

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Marco insert # of row specific in a cell

    Happy to help.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,510

    Re: Marco insert # of row specific in a cell

    You're welcome.

  7. #7
    Registered User
    Join Date
    05-06-2011
    Location
    New York, US
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: [more help] Marco insert # of row specific in a cell

    Quote Originally Posted by TMShucks View Post
    You're welcome.
    I am greedy... and want to to build the Marco from scratch with the oringal file: see file as: Monkey.xls

    Part 1:
    Re-listing from A2 in order (1,2,3) - stop when it reaches [Total]

    Part 2:
    Insert 3 column after [G column]
    the new columns need to be named as follow:

    new [H column] "Carton (Qty.)"
    new [I column] "Case Number"
    new [J column] "Carton Label #"

    Next, action the code that written by Marcol (addrow and number new row]

    After this, I need to add one more Marco:

    in Column J, from:
    J2 = listing as: Carton 1 of (Max#) in column A
    J3 - listing as: Carton 2 of (Max#) in column A

    Continue and stop when the [Total] is reached in column A

    the final file should look like as attached: wolf.xls
    Attached Files Attached Files

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Macro to insert # of row specific in a cell

    Please stop editing your title... this is the 3rd time that I fixed it... just add your new post to the thread and somebody will look at it.

    Thank you!
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  9. #9
    Registered User
    Join Date
    05-06-2011
    Location
    New York, US
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Macro to insert # of row specific in a cell

    Quote Originally Posted by NBVC View Post
    Please stop editing your title... this is the 3rd time that I fixed it... just add your new post to the thread and somebody will look at it.

    Thank you!
    new user here....sorry for the inconvenience it caused to you and thanks for the fixed.

  10. #10
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Macro to insert # of row specific in a cell

    Try this with your Sheet "Tiger"
    Please Login or Register  to view this content.

    Hope this helps.

  11. #11
    Registered User
    Join Date
    05-06-2011
    Location
    New York, US
    MS-Off Ver
    Excel 2007
    Posts
    25

    Question Re: Macro to insert # of row specific in a cell

    Quote Originally Posted by Marcol View Post
    Try this with your Sheet "Tiger"
    Please Login or Register  to view this content.

    Hope this helps.
    Marco:

    the add J column for Carton 1 of 35 is wokring.
    however, part 1 and Part 2 where i needed in the Monkey file is not working.

    appreciated if you can re-look the monkey file
    also, is there any way not to rename the sheet2 to" tiger"

    thanks for your help!

  12. #12
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Macro to insert # of row specific in a cell

    Post a sensible workbook.
    Forget the Lion, the Tiger, and the Turkey Buzzard.
    Put your problem in one workbook, simple names like "Sheet1", "Sheet2", etc will suffice.

    A simple before and after example is usually enough.

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,510

    Re: Macro to insert # of row specific in a cell

    @Marcol: Turkey Buzzard? Missed that one ;-)

  14. #14
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Macro to insert # of row specific in a cell

    @ TMShucks
    It's a workbook after "Aardvark" and before "Zebra", but it's on a different server.

  15. #15
    Registered User
    Join Date
    05-06-2011
    Location
    New York, US
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Macro to insert # of row specific in a cell

    Quote Originally Posted by Marcol View Post
    Post a sensible workbook.
    Forget the Lion, the Tiger, and the Turkey Buzzard.
    Put your problem in one workbook, simple names like "Sheet1", "Sheet2", etc will suffice.

    A simple before and after example is usually enough.
    Applogies Marcol, my DD has alot of stuff animals in the house. so thought it would be easy when recall. next time i will use flowers like, Lilly, Rose and Jasmine... LOL

    okay, basically this is what i want:

    - Relisting in [A column] in an increasement order from A2 (1,2,3) stop when it reaches [Total]. A2 was=1001, A3 was 1002

    Next
    - Insert 3 columns after [G column]
    the new columns need to be named as follow:

    new [H column] "Carton (Qty.)"
    new [I column] "Case Number"
    new [J column] "Carton Label #"

    Next
    - in [H column], =G2/12, =G3/12 - stop when it reaches the last # in [G colunm]

    at last, i will execute the code that written by Marcol on the above.
    in case, you want to see the sample file i am attaching [before] and [after] file.
    thanks for all the help!
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    05-06-2011
    Location
    New York, US
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Macro to insert # of row specific in a cell

    @ Marcol
    Can u help ??

  17. #17
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Macro to insert # of row specific in a cell

    This is not how I would normally code this but as I can't fully understand what you finally want as a result. I have broken the code into several subs so that you can easily comment them out in the macro "Convert Sheet", or edit the individual subs.

    The numbering you have asked for in "Line" seems to me, to be at odds with what you ask for in "Carton Label#".

    Please Login or Register  to view this content.

    "Sheet1" is a copy of your before sheet ("monkey"?), the code will convert "Sheet1"
    To convert one of the sheets from your DDs' stuffed animals colection change ths line in the sub "ConvertSheet"
    Please Login or Register  to view this content.
    e.g.
    Please Login or Register  to view this content.

    Hope this helps

    [EDIT]
    If the line numbers are to be 1001, 1002, etc
    Change these lines in Sub RenumberLines
    Please Login or Register  to view this content.
    To
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Marcol; 05-08-2011 at 08:52 AM.

  18. #18
    Registered User
    Join Date
    05-06-2011
    Location
    New York, US
    MS-Off Ver
    Excel 2007
    Posts
    25

    Thumbs up Re: Macro to insert # of row specific in a cell

    Quote Originally Posted by Marcol View Post
    This is not how I would normally code this but as I can't fully understand what you finally want as a result. I have broken the code into several subs so that you can easily comment them out in the macro "Convert Sheet", or edit the individual subs.

    The numbering you have asked for in "Line" seems to me, to be at odds with what you ask for in "Carton Label#".

    Please Login or Register  to view this content.

    "Sheet1" is a copy of your before sheet ("monkey"?), the code will convert "Sheet1"
    To convert one of the sheets from your DDs' stuffed animals colection change ths line in the sub "ConvertSheet"
    Please Login or Register  to view this content.
    e.g.
    Please Login or Register  to view this content.

    Hope this helps

    [EDIT]
    If the line numbers are to be 1001, 1002, etc
    Change these lines in Sub RenumberLines
    Please Login or Register  to view this content.
    To
    Please Login or Register  to view this content.

    @Marcol,
    i wanted to take the time and thank you! the code works perfectly! you are amazing!!
    thanks again for taking your time to help me! I'm truly grateful!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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