+ Reply to Thread
Results 1 to 13 of 13

Delete rows in worksheet using VBA

  1. #1
    Registered User
    Join Date
    01-04-2013
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    9

    Delete rows in worksheet using VBA

    Hi, I have a situation (below) I want to delete the first three rows repeatly (I updated the file to make it clearer)

    row1: aaaa -> delete
    row2: bbbb -> delete
    row3: cccc-> delete
    row4: Company name A
    row5: data
    row6: data
    ....
    row9: data
    row10: dddd -> delete
    row11: eeee -> delete
    row12: rrrrr -> delete
    row13: Company name B
    row14: data
    row15: data
    .......
    row18: data
    row19:fffff -> delete
    ....
    1xxxx rows repeated like this
    Thank you so much
    Attached Files Attached Files
    Last edited by arlu1201; 02-21-2013 at 05:25 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: Delete rows in worksheet using VBA

    Hi

    Post sample data file.
    Click *, if my suggestion helps you. Have a good day!!

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete rows in worksheet using VBA

    Is there any data in a particular cell looking at which, we can delete the 3 rows prior to it or 3 rows after it?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Delete rows in worksheet using VBA

    May be this...

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  5. #5
    Registered User
    Join Date
    01-04-2013
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Delete rows in worksheet using VBA

    Thank you for your help
    But it seems the code doesn't work they way I want maybe you can have a look on my attached file to see a clear example
    Thank again
    Last edited by arlu1201; 02-21-2013 at 03:59 AM. Reason: Do not quote whole posts.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete rows in worksheet using VBA

    Try this code -
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

  7. #7
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Delete rows in worksheet using VBA

    Try this...

    Please Login or Register  to view this content.

  8. #8
    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: Delete rows in worksheet using VBA

    1/. Put this in a spare column, say Column D
    In D1, Drag/Fill Down.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    2/. Filter this column for "Delete"

    3/. Select and Delete the resulting Rows, Edit > Delete Row

    4/. Remove the filter, if not automatically done by your selection.

    VBa isn't required, and this gives a visual check of what you are deleting.

    Also this method is easier and more versatile than VBa.

    [EDIT]
    If your data is consistant, you might not need to wrap A1 in PROPER().
    Last edited by Marcol; 02-21-2013 at 04:32 AM. Reason: Typos
    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.

  9. #9
    Registered User
    Join Date
    01-04-2013
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Delete rows in worksheet using VBA

    Quote Originally Posted by Marcol View Post
    1/. Put this in a spare column, say Column D
    In D1, Drag/Fill Down.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    2/. Filter this column for "Delete"

    3/. Select and Delete the resulting Rows, Edit > Delete Row

    4/. Remove the filter, if not automatically done by your selection.

    VBa isn't required, and this gives a visual check of what you are deleting.

    Also this method is easier and more versatile than VBa.

    [EDIT]
    If your data is consistant, you might not need to wrap A1 in PROPER().
    End 2012 (I want to delete)
    Frequency Y ((I want to delete))
    Name 1ST SOFTWARE DEAD - DELIST.06/10/08 ((I want to delete)
    Code T:ISOF(P)
    2012 0.02
    2011 0.02
    2010 0.02
    2009 0.02
    2008 0.02

    so the data become
    Code T:ISOF(P)
    2012 0.02
    2011 0.02
    2010 0.02
    2009 0.02
    2008 0.02

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete rows in worksheet using VBA

    You need to try the formula through the steps given by Marcol in post 8 and let all know if it works.

  11. #11
    Registered User
    Join Date
    01-04-2013
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Delete rows in worksheet using VBA

    Quote Originally Posted by arlu1201 View Post
    You need to try the formula through the steps given by Marcol in post 8 and let all know if it works.
    I try already but it doesn't work the way I want. I receive a solution and it works. I will post under the topic so the others may use when they need


    Thank 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: Delete rows in worksheet using VBA

    That seems to be a completly different question.

    Post another workbook showing the data before and after conversion.

    Are you looking to delete groups of data rather than just certain rows?

  13. #13
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete rows in worksheet using VBA

    Do not post your solution in the 1st post as it may confuse other users who are browsing your thread. Instead you can post it as the last post of this thread.

    To mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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