+ Reply to Thread
Results 1 to 7 of 7

Macros to insert 2 blank row and autosum a column after every 200 rows in data range.

  1. #1
    Registered User
    Join Date
    10-20-2012
    Location
    New Delhi
    MS-Off Ver
    Excel 2003
    Posts
    3

    Macros to insert 2 blank row and autosum a column after every 200 rows in data range.

    Hello Everybody,

    The challenge is that i have an excel with Data Range from A1:AH40000 and i want to insert 2 blank rows after every 200 rows and in first blank row i want the Auto sum of column "N" just to start i am using the following coding to insert rows which works perfectly but i am stuck on how to do the autosum part:

    Sub InsertRows()
    Dim i As Long, nRows As Integer, nEvery As Integer
    Application.ScreenUpdating = False
    nRows = 2 'number of rows to insert
    nEvery = 200 'number of rows to skip between insertions
    i = nEvery + 1 'first row for insertion
    While Not IsEmpty(Cells(i, 1)) 'stop inserting when come to empty cell
    Rows(i & ":" & i + nRows - 1).Insert
    i = i + nRows + nEvery
    Wend
    End Sub

    Please assist..

  2. #2
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Kolkata, India
    MS-Off Ver
    Excel 2003/2007
    Posts
    182

    Re: Macros to insert 2 blank row and autosum a column after every 200 rows in data range.

    Hi,

    Add below codes with the codes you have created.

    Please Login or Register  to view this content.
    If require change the codes as per your requirement.


    Regards
    taps

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macros to insert 2 blank row and autosum a column after every 200 rows in data range.

    Another:

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Kolkata, India
    MS-Off Ver
    Excel 2003/2007
    Posts
    182

    Re: Macros to insert 2 blank row and autosum a column after every 200 rows in data range.

    Hi John,

    Your function is working fine. It is really a nice work.


    Regards
    taps

  5. #5
    Registered User
    Join Date
    10-20-2012
    Location
    New Delhi
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Macros to insert 2 blank row and autosum a column after every 200 rows in data range.

    Hi Taps,

    This is what i have done but seems there is some error in calculation: (here i Admit that i am new to VBA) may be i havent done it right.

    Sub InsertRows2()
    Dim i As Long, nRows As Integer, nEvery As Integer
    Dim LastRow As Long
    Dim TempVal As Double
    Application.ScreenUpdating = False
    nRows = 2 'number of rows to insert
    nEvery = 200 'number of rows to skip between insertions
    i = nEvery + 1 'first row for insertion
    While Not IsEmpty(Cells(i, 1)) 'stop inserting when come to empty cell
    Rows(i & ":" & i + nRows - 1).Insert
    i = i + nRows + nEvery
    Wend
    'Find the last row to continue the Do loop
    Range("A65536").End(xlUp).Select
    LastRow = ActiveCell.Row
    TempVal = 0

    'We assume that amount is in B column
    Range("N2").Select ' Start checking amount from second row to avoid error in If condition below
    Do While ActiveCell.Row <= LastRow + 1
    TempVal = TempVal + ActiveCell.Value

    If ActiveCell.Offset(0, -1) = "" And ActiveCell.Offset(-1, -1) <> "" Then
    ActiveCell.Value = TempVal
    TempVal = 0
    End If

    ActiveCell.Offset(1, 0).Select
    Loop
    End Sub

  6. #6
    Registered User
    Join Date
    10-20-2012
    Location
    New Delhi
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Macros to insert 2 blank row and autosum a column after every 200 rows in data range.

    Hi John

    your code is working perfectly just as i wanted

    Thanks boss..

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macros to insert 2 blank row and autosum a column after every 200 rows in data range.

    You're welcome. Glad to help out and thanks for the feedback. Please comply with Forum Rule No. 9. Acknowledge the responses you receive, good or bad. If your problem is solved, please say so clearly, and mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Dropdown option or Edit button will not appear -- ask a moderator to mark it.

+ 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