Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 23

Thread: Insert a new row after a certain number of rows

  1. #1
    VBAX Regular
    Joined
    Dec 2006
    Posts
    18
    Location

    Insert a new row after a certain number of rows

    Hi Everyone,

    I am working with Excel 2003.

    I want to insert a new row after a certain number of rows. For example, I want to insert a new row every 30 rows, and also insert a new row after every 45 rows. Anyone know how to do this?

    I also want to for example, bolded and underline (modify the format) every 10 rows in a specific column(s) or cell rather.

    Is it the same with indenting certain cells?
    Thanks in Advance!

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Sorry, don't quite follow...

    You want to insert a row at 30, 45, 60, 105, etc...? OR 30, 75, 105, 150... Or...?

    Can you give the sequence of the rows?
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    VBAX Regular
    Joined
    Dec 2006
    Posts
    18
    Location
    Quote Originally Posted by Ken Puls
    Sorry, don't quite follow...

    You want to insert a row at 30, 45, 60, 105, etc...? OR 30, 75, 105, 150... Or...?

    Can you give the sequence of the rows?
    Let's say for every customer I have on my list, takes 39 rows. My data starts at row 4, I need to insert a new row at row: 13, 23, 28, 36, 40, and 43 (these new rows are inserted for 1st customer and the pattern repeats itself). 2nd customer, new rows would be at row 44+13, 44+23, ... 44+43=77.

    Hope this is what you are asking for.

    Thanks for the help.
    Last edited by tialongz; 12-15-2006 at 01:00 PM.

  4. #4
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    I think a visual aid is needed here. Could you post a sample?

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I may be thick, but 30 and 45 looks slightly different to 13, 23, 28, 36, 40, and 43 to me.

  6. #6
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Quote Originally Posted by xld
    I may be thick, but 30 and 45 looks slightly different to 13, 23, 28, 36, 40, and 43 to me.
    Maybe a new style of math that we're not aware of?
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  7. #7
    VBAX Regular
    Joined
    Dec 2006
    Posts
    18
    Location
    Quote Originally Posted by austenr
    I think a visual aid is needed here. Could you post a sample?
    I cannot upload at the moment, but if you could go to this link, I posted a sample, how the excel file looks like.

    I'll post the link on the next post. I didn't know I need to post 5 posts, to be able to include a link.

    It has like 4 screen shots, i think the third one is the excel file, I need to sum all the products for each of the business. But there is a need to insert a new row so I could do autosum function. This is just a dummy data, on the actual one, all the customers will have the same amount of rows, and same businesses, and products.

    Hope this clarify a tad
    thanks in advance

  8. #8
    VBAX Regular
    Joined
    Dec 2006
    Posts
    18
    Location
    Here is the link:
    http://www.dbforums.com/showthread.php?t=1612438 (go to the last post)

  9. #9
    VBAX Regular
    Joined
    Dec 2006
    Posts
    18
    Location
    Quote Originally Posted by Ken Puls
    Maybe a new style of math that we're not aware of?
    I hope this does not implicate things.

    But all customers have the exactly the same 39 rows. It is basically copying and pasting the same 39 rows over and over again, just under different customer names.

  10. #10
    Mac Moderator VBAX Expert shades's Avatar
    Joined
    May 2004
    Location
    Kansas City, USA
    Posts
    638
    Location
    So, this means that you could search for the name and then insert the 39 rows one row below the name that SEARCH/FIND provides?

    Software: LibreOffice 3.3 on Mac OS X 10.6.5
    (retired Excel 2003 user, 3.28.2008 )
    Humanware: Older than dirt
    --------------------
    old, slow, and confused
    but at least I'm inconsistent!

    Rich

  11. #11
    VBAX Regular
    Joined
    Dec 2006
    Posts
    18
    Location
    Quote Originally Posted by shades
    So, this means that you could search for the name and then insert the 39 rows one row below the name that SEARCH/FIND provides?
    I guess in a way, if I am understanding you correctly.

    You seen my screenshots, if you just ignore the first company, and imagin the format of the second company repeated over and over again, but under different names. Like there is no extra row between businesses, so I couldn't use the autosum function to get the sums for each of businesses for each company.

  12. #12
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    try
    [vba]Option Explicit

    Sub AddRows()
    Dim LRw As Long
    Dim rng As Range
    Dim i As Long

    Application.ScreenUpdating = False
    LRw = Cells(Rows.Count, 1).End(xlUp).Row - 38
    For i = LRw To 4 Step -39
    Set rng = Union(Cells(i + 9, 1), Cells(i + 18, 1), Cells(i + 22, 1), _
    Cells(i + 29, 1), Cells(i + 32, 1), Cells(i + 34, 1), Cells(i + 39, 1))
    rng.EntireRow.Insert
    Set rng = Nothing
    Next
    Application.ScreenUpdating = True
    End Sub

    [/vba]
    Last edited by mdmackillop; 12-18-2006 at 03:38 PM. Reason: Code amended to add missing row
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  13. #13
    VBAX Regular
    Joined
    Dec 2006
    Posts
    18
    Location
    Quote Originally Posted by mdmackillop
    try
    [vba]Option Explicit

    Sub AddRows()
    Dim LRw As Long
    Dim rng As Range
    Dim i As Long

    Application.ScreenUpdating = False
    LRw = Cells(Rows.Count, 1).End(xlUp).Row - 38
    For i = LRw To 4 Step -39
    Set rng = Union(Cells(i + 9, 1), Cells(i + 18, 1), Cells(i + 22, 1), _
    Cells(i + 29, 1), Cells(i + 32, 1), Cells(i + 39, 1))
    rng.EntireRow.Insert
    Set rng = Nothing
    Next
    Application.ScreenUpdating = True
    End Sub
    [/vba]
    I tried it. But the new rows are inserted at the wrong places. My first row (or first customer) starts at row4, 2nd starts at row 43, 82 and so on.

    For my first customer, I need to insert new rows at row 13, 23, 28, 36,40 and 43. For my second customers, new rows need to be inserted at 13+39, 23 +39.....43+39.

    If you could, please explain the code, so maybe I could try to modify it or..test it. I tried to change those numbers in the brackets, still no luck.

    Not sure if this helpful, but there might be a empty space at row 13, 23, or 28. Because other columns at row 13, 23 or 28 might have data in them, I am trying to insert a row so.. all columns are empty.

    Thanks in advance.
    Last edited by tialongz; 12-18-2006 at 01:38 PM.

  14. #14
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Did you ever read a thread and end up saying "What?" That is how I feel reading this.

    I read the link the OP provided. I think that the data he has either needs to be delt with totally in Access (which is where the report in the link is generated), or import the raw data to a workbook (Data>Import External Data) and proceed from there. Something is getting lost in the translation, IMHO.

    Apparently there is a learning curve to deal with as well. IMHO.

  15. #15
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    The sample I supplied will insert new rows numbered 13, 23, 28, 36,40 and 43, and also between Customers. FYI, because rows are being inserted, new rows are inserted in the last Customer first. If you want the new lines in different positions, just change the + numbers in the code to suit.
    If this is not what you are after, please make up a simple sample showing exactly what you want and post it using Manage Attachments in the Go Advanced section. Your link made no sense to me.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  16. #16
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Ok let me give this a shot. Starting at row 4 which is the first row of your first customer, you want a blank row inserted after these rows 13, 23, 28, 36,40 and 43. Row 43 would be a blank row immediatly under the last row of data for customer 1.

    Then beginning at row 44, (the first row of data for customer 2), count 9 rows and insert a blank row, 10 more rows and insert a row, 5 rows and insert a row, 8 rows and insert a blank row, 4 rows then a blank row and three rows and insert a blank row.

    The cycle then repeats for the third customer?

    Is that even close to being what you are after?

    And the obvious question (well maybe not, what will the blank row be used for?) If its for totaling then there is a far easier way to do what you want.

  17. #17
    VBAX Regular
    Joined
    Dec 2006
    Posts
    18
    Location

    Wink

    Quote Originally Posted by austenr
    Ok let me give this a shot. Starting at row 4 which is the first row of your first customer, you want a blank row inserted after these rows 13, 23, 28, 36,40 and 43. Row 43 would be a blank row immediatly under the last row of data for customer 1.

    Then beginning at row 44, (the first row of data for customer 2), count 9 rows and insert a blank row, 10 more rows and insert a row, 5 rows and insert a row, 8 rows and insert a blank row, 4 rows then a blank row and three rows and insert a blank row.

    The cycle then repeats for the third customer?

    Is that even close to being what you are after?

    And the obvious question (well maybe not, what will the blank row be used for?) If its for totaling then there is a far easier way to do what you want.
    Yes, I know. I will try to clarify a bit.
    To answer you obvious question, yes I am inserting the new rows so I could do the subtotals. (I need the totals for the products for each of the businesses.)

    I tried to use the subtotal function and applies to the entire sheet, but the total rows are showing up at the wrong places.

    I have attached an excel file, I want subtotals after the last product of each business.

    Thanks in advance.

  18. #18
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location
    Hello tialongz,
    I've added to the last sample you give ... maybe this can help?
    I
    Thank you for your help

  19. #19
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by tialongz
    I have attached an excel file, I want subtotals after the last product of each business.
    Why does your sample not relate to the descriptions in your questions? I still don't know where the "wrong" positions are.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  20. #20
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Is this what you want?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •