+ Reply to Thread
Results 1 to 6 of 6

Insert, shift cells down and populate

Hybrid View

  1. #1
    Registered User
    Join Date
    11-22-2007
    Posts
    42

    Insert, shift cells down and populate

    Good morning,

    I have a range of cells in a sheet that I am wanting to insert data in to and then populate with data. (there is other information in the rows so I dont want insert rows.

    I have the following for the insert, but the populate is very manual

     Range("K6:L6").Select
        Selection.Insert Shift:=xlDown
    Currently I have the populate as a cell reference, but this list may change regularly.

    Range("K3").Select
        ActiveCell.FormulaR1C1 = "Script"
        Range("L3").Select
        ActiveCell.FormulaR1C1 = "Target"
        Range("K4").Select
        ActiveCell.FormulaR1C1 = "DL1  "
        Range("L4").Select
        ActiveCell.FormulaR1C1 = "0.32"
        Range("K5").Select
        ActiveCell.FormulaR1C1 = "DV9  "
        Range("L5").Select
        ActiveCell.FormulaR1C1 = "0.32"
        Range("K6").Select
        ActiveCell.FormulaR1C1 = "ED2  "
        Range("L6").Select
        ActiveCell.FormulaR1C1 = "0.77"
        Range("K7").Select
        ActiveCell.FormulaR1C1 = "DX8  "
        Range("L7").Select
        ActiveCell.FormulaR1C1 = "0.77"
    Is there a way that I can have the cells insert and populate the next cells down rather than including a cell reference? The above is just a sample. I have a heap that I need to insert (and change) on a regular basis.

  2. #2
    Registered User
    Join Date
    11-22-2007
    Posts
    42

    ok....moving on

    I have found this at another website....

    Is this the best way of doing it?
    ActiveCell.Offset(1, 0).Select
    ActiveCell.FormulaR1C1 = "Script"
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "Target"
    ActiveCell.Offset(1, -1).Select
    ActiveCell.FormulaR1C1 = "DL1  "
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "0.32"
    ActiveCell.Offset(1, -1).Select
    ActiveCell.FormulaR1C1 = "DV9  "
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "0.32"
    ActiveCell.Offset(1, -1).Select
    Last edited by royUK; 12-04-2007 at 02:48 AM.

  3. #3
    Registered User
    Join Date
    11-22-2007
    Posts
    42

    offset next cell selection

    is this the best way of going about this? or is there a better/easier way?

    Sub inserttargets()
    '
    ' inserttargets Macro
    ' This macro will insert targets
    '
    
    '
    Range("K2").Select
    ActiveCell.Offset(1, 0).Select
    ActiveCell.FormulaR1C1 = "Script"
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "Target"
    ActiveCell.Offset(1, -1).Select
    ActiveCell.FormulaR1C1 = "DL1  "
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "0.32"
    ActiveCell.Offset(1, -1).Select
    ActiveCell.FormulaR1C1 = "DV9  "
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "0.32"
    ActiveCell.Offset(1, -1).Select
    ActiveCell.FormulaR1C1 = "ED2  "
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "0.77"
    ActiveCell.Offset(1, -1).Select
    ActiveCell.FormulaR1C1 = "DX8  "
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "0.77"
    ActiveCell.Offset(1, -1).Select
    ActiveCell.FormulaR1C1 = "DZ3"
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "0.80"
    ActiveCell.Offset(1, -1).Select
    ActiveCell.FormulaR1C1 = "DZ5  "
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "1.00"
    ActiveCell.Offset(1, -1).Select
    ActiveCell.FormulaR1C1 = "DZ6  "
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "0.80"
    ActiveCell.Offset(1, -1).Select
    ActiveCell.FormulaR1C1 = "DZ7  "
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "0.80"
    ActiveCell.Offset(1, -1).Select
    ActiveCell.FormulaR1C1 = "DZ8  "
    ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "0.77"
    ActiveCell.Offset(1, -1).Select
    End Sub
    Thanks for looking

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    With Range("K3:K12")
        .Offset(0, 0).Value = Application.Transpose(Array("Script", "DL1", "DV9", "ED2", "DX8", "DZ3", "DZ5", "DZ6", "DZ7", "DZ8"))
        
        .Offset(0, 1).Value = Application.Transpose(Array("Target", 0.32, 0.32, 0.77, 0.77, 0.8, 1, 0.8, 0.8, 0.77))
    End With
    Range("K13").Select

  5. #5
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565
    Hi there,

    It's much simplier, easier to read/follow and quicker if you just reference the relevant cell you want to manipulate, i.e.

    Range("K3").Formula = "Script"
    Range("K4").Formula = "DL1"
    Range("K5").Formula = "DV9"
    Range("K6").Formula = "ED2"
    Range("K7").Formula = "DX8"
    Range("K8").Formula = "DZ3"
    Range("K9").Formula = "DZ5"
    Range("K10").Formula = "DZ6"
    Range("K11").Formula = "DZ7"
    Range("K12").Formula = "DZ8"
    
    Range("L3").Formula = "Target"
    Range("L4").Formula = "0.32"
    Range("L5").Formula = "0.32"
    Range("L6").Formula = "0.77"
    Range("L7").Formula = "0.77"
    Range("L8").Formula = "0.8"
    Range("L9").Formula = "1"
    Range("L10").Formula = "0.8"
    Range("L11").Formula = "0.8"
    Range("L12").Formula = "0.77"
    HTH

    Robert

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    That code is inefficient, you do not need to select the cells. Also, read the Forum Rules & use Code tags when posting code.

    ActiveCell.Offset(1, 0). FormulaR1C1 ="Script"
    ActiveCell.Offset(0, 1).FormulaR1C1 = "Target"
    ActiveCell.Offset(1, -1).FormulaR1C1 = "DL1 "
    ActiveCell.Offset(0, 1).FormulaR1C1 = "0.32"
    ActiveCell.Offset(1, -1).FormulaR1C1 = "DV9 "
    ActiveCell.Offset(0, 1).FormulaR1C1 = "0.32"
    ActiveCell.Offset(1, -1).Select
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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