Consulting

Results 1 to 3 of 3

Thread: insert a row

  1. #1

    insert a row

    OK this should be simple; I want to insert a new row into a range; but it just doesn't work
    [VBA]
    Function tt() As Integer
    tt = 0
    Dim ttt As Range
    Dim CRange As Range
    Dim CStore As Range

    Set CStore = ActiveSheet.Cells(4, 4)
    MsgBox (CStore.Address)
    Set CRange = Range(ActiveSheet.Cells(4, 4).Value)
    MsgBox (CRange.Address)
    'Set ttt = Range(Cells(CRange.row + 1, CRange.Column), Cells(CRange.row + 1, CRange.Column + 2))
    Set ttt = CRange.Rows(2)
    MsgBox (ttt.Address)
    'ttt.Select
    'Selection.
    ttt.Insert Shift:=xlDown ', CopyOrigin:=xlFormatFromLeftOrAbove

    tt = 1
    End Function
    [/VBA]

    its got two problems
    * It loops before the second message box although the addresses are correct; the messageboxes display
    $d$4
    $d$4
    $g$8:$i$10
    $g$9:$i$9

    * it doesn't insert a row.

    Sorry my brain died a while ago; Can anyone see whats wrong with it?

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    Try

    [VBA]
    Set ttt = CRange.Rows(2).EntireRow
    [/VBA]

    Paul

  3. #3
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    You don't really need ttt. You could simply use:
    [vba]CRange.Rows(2).EntireRow.Insert[/vba]
    And CStore isn't used at all so you could get rid of it.
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

Posting Permissions

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