+ Reply to Thread
Results 1 to 11 of 11

Insert Rows, Copy & Pasting on VBA

  1. #1
    Registered User
    Join Date
    07-26-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    18

    Insert Rows, Copy & Pasting on VBA

    Hi guys,

    I was wondering if you can help me with this problem. I would like to solve this in VBA. Attached is an excel file where Sheet1 is the current state and Sheet2 is what I would like to achieve. Basically, in column A, for each cluster of rows with similar Numbers I will need to insert the same cluster of rows below. The Number will subsequently change to reflect a new starting digit before "-". All digits after "-" is similar to before. In column B, the Value in the inserted rows will be the same as previously, but all to be negative. Finally, in column C, I would just like the exact copy of the Description in the above cells to be pasted in the inserted rows in the same column. You can refer to the excel if I am not doing a good job in explaining my problem. It will be nice to be able to program the highlighting colour for the inserted cells as well. Thank you in advance.
    Attached Files Attached Files

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Insert Rows, Copy & Pasting on VBA

    Maybe :
    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Insert Rows, Copy & Pasting on VBA

    This seems to do what you've described.
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    07-26-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    18

    Re: Insert Rows, Copy & Pasting on VBA

    Quote Originally Posted by JBeaucaire View Post
    This seems to do what you've described.
    Please Login or Register  to view this content.
    Hi JBeaucaire,

    Thanks for the reply. Your code works very well. Now I have a slight adaptation to the problem. The Column A Numbers in the inserted rows will now be tagged to the Description. Again, all numbers that occur after "-" is the same as the above cells, but numbers preceding "-" are now to be changed to reflect the alphabet sequence. For eg, if Description states "RECL FOR A" then the number before "-" should be 1. If Description states "RECL FOR B" then the number before "-" should be 2. I have attached the new excel file reflecting what I have just described for your reference. Would appreciate your guidance in this. Thank you.
    Attached Files Attached Files

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Insert Rows, Copy & Pasting on VBA

    Tweaked.

    Please Login or Register  to view this content.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  6. #6
    Registered User
    Join Date
    07-26-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    18

    Re: Insert Rows, Copy & Pasting on VBA

    Thank you JBeaucaire, just one more query before I close this thread. I would like to code 26 cases for the alphabetically-tagged Number instead of using Asc. Can you point me in the right direction for just 1 alphabet example? Thanks.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Insert Rows, Copy & Pasting on VBA

    I don't understand the question. A few examples?

  8. #8
    Registered User
    Join Date
    07-26-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    18
    Quote Originally Posted by JBeaucaire View Post
    I don't understand the question. A few examples?
    Hi JBeaucaire, basically I don't want to use asc function to tag the alphanumeric sequence. Which means I would like to use If...ElseIf. For eg,

    If arrOLD(Rw, 3) = "RECL FOR A" Then
    arrNEW(Rw, 1) = "1" & newNUM
    ElseIf arrOLD(Rw, 3) = "RECL FOR B" Then
    arrNEW(Rw, 1) = "2" & newNUM

    Of course, I've tried the above code but it doesn't work. Can you help me?

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Insert Rows, Copy & Pasting on VBA


  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Insert Rows, Copy & Pasting on VBA

    I'm not going to compete with other forums for this topic. You can continue over there.

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Insert Rows, Copy & Pasting on VBA

    Something simple and editable like:

    Please Login or Register  to view this content.

+ 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. Copy and Pasting Rows given a cell value
    By dbryson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2016, 11:12 PM
  2. [SOLVED] Copy and pasting (through vba) specific rows to new sheet
    By JPSIMMON in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 08-30-2015, 11:29 PM
  3. [SOLVED] Copy & pasting at random number of rows using VBA
    By aoni in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-29-2015, 08:52 AM
  4. [SOLVED] VBA codes to insert the rows and copy the first entire row text and insert sheet
    By PRADEEPB270 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2013, 05:05 AM
  5. Replies: 1
    Last Post: 10-31-2012, 05:17 AM
  6. [SOLVED] Copy and Pasting multiple rows of containing certain data
    By samel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-07-2012, 03:09 PM
  7. Copy and pasting auto-sorted rows in sequence
    By PaulEku in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-23-2008, 12:25 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