Consulting

Results 1 to 5 of 5

Thread: Insert N cells for M new rows?

  1. #1

    Insert N cells for M new rows?

    Hi everybody!
    Im trying to insert N cells (fx 4) as a row, m (fx 5) times, i.e. i would like to insert NxM cells, where A2 is the first of them.
    The reason it cannot be an entire row, is that i have a graph next to my data, and it's not so neat that when i push down cells i shift the graphs down as well. Tried google, but usualy people only insert multiple, entire rows.

    Does anybody know how to do this in VBA?

  2. #2
    Im currently using this one, to insert N rows (in this case N = iWeather)
    shtHis.Range("A2", shtHis.Cells(2, iWeather + 1)).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

    But i would like to do this M times? There must be a smarter way of doing this than a loop!

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "A beggar of love, second hand hero...King of Dreams"
    Posts
    2,597
    hi JKB

    can you add a file with two sheets which display before and after macro table structure?
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    Knowledge Base Approver VBAX Guru
    Joined
    Apr 2012
    Posts
    4,863
    In Excel you can't 'add/insert' rows nor columns: rows.count and columns.count are fixed.
    In your case I'd consider moving the graph 5 columns to the right.

  5. #5
    Okay... The problem was embarrissingly simple! You just define the range you want to insert, fx:
    sht.Range("A2", sht.Cells(N, M)).Insert shift:=xlDown, copyorigin:=xlFormatFromLeftOrAbove

    If somebody else ever should have this problem!

Tags for this Thread

Posting Permissions

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