+ Reply to Thread
Results 1 to 10 of 10

VBA Macro needed to delete X amount of rows below the Nth row

  1. #1
    Registered User
    Join Date
    10-28-2012
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2010
    Posts
    5

    VBA Macro needed to delete X amount of rows below the Nth row

    Thanks in advance for the help.
    I have a set of data with a dynamic number or rows. Could be 10, could be 1000. I want to find the last row of data before any spaces, and delete the next 12 rows. Any help would be great!

    I added a sample file of what I'm trying to get accomplished. For the file attached, I want the macro to find the cell after 78627(A:20) and delete the next 12 rows. The rows are dynamic, so the formula needs to be able to recognize the first blank cell whether it happens to be A:5 or A:1000.

    Thanks for the help, I know this is a tough one.
    Attached Files Attached Files
    Last edited by jsirish; 11-02-2012 at 08:51 AM. Reason: I updated the attachment

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: VBA Macro needed to delete X amount of rows below the Nth row

    Hi, jsirish,

    maybe try soimethin glike this on a copy of the workbook:

    Please Login or Register  to view this content.
    Code goes into a standard module and may be called either by placing the cursor into the procedure and press F5 (run entire procedure) or F8 (single step through).

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    10-28-2012
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: VBA Macro needed to delete X amount of rows below the Nth row

    That Gives me a run-time error 1004. I like the idea with the resize function, but it must be missing something?

  4. #4
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: VBA Macro needed to delete X amount of rows below the Nth row

    Your statement is a little bit confusion, but try
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-28-2012
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: VBA Macro needed to delete X amount of rows below the Nth row

    That seems to delete the rows, however it deletes 12 rows below where the current active cell is. How do I reference the first blank cell after the count function?

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: VBA Macro needed to delete X amount of rows below the Nth row

    Hi, jsirish,

    code was tested on your sample workbook and worked fine there. 1004 may i.e appear if the whole range is filled up to the last cell in the column (CTRL + Down) which wasnīt hte case in the example.

    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    10-28-2012
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: VBA Macro needed to delete X amount of rows below the Nth row

    It seems to be performing the delete function before it gets down to the bottom of the column?

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: VBA Macro needed to delete X amount of rows below the Nth row

    Hi, jsirish,

    It seems...
    Hmm - code doesnīt seem not to do what itīs supposed to do (at least for me in the example ).

    You delivered a sample, starting with a block of data in Range("A4"). The code starts from that cell, goes down to the last filled cell without blanks in Column A, then goes one row below and builds a range of 12 cells in Column A where the rows are deleted.

    Starting from any cell iside the block except for the last cell will have the same result. Different results will be achieved if you start in Range("A19") where no run time error would occur but rows from Row 22 would be deleted.

    Form your information Row 32 in Sheet 1 will not be deleted as that would be 13 rows below the given number which happens to be in A19.

    HTH
    Holger

  9. #9
    Registered User
    Join Date
    10-28-2012
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: VBA Macro needed to delete X amount of rows below the Nth row

    I Attached a new file to the first post that is in the exact format of the file I'm trying to work with. Possibly the other file was too different. Can anyone help??

    Again, what I'm trying to do is delete everything after row 19 on this spreadsheet. However, the rows will be dynamic so in one case it might be deleting everything after row 5, and in others it will be deleting everything after row 1000.

    Thanks in advance!!

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: VBA Macro needed to delete X amount of rows below the Nth row

    Hi, jsirish,

    a slightly different approach for now:

    Please Login or Register  to view this content.
    Ciao,
    Holger

+ 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