PDA

View Full Version : insert a row



mattrix
12-13-2012, 03:21 AM
OK this should be simple; I want to insert a new row into a range; but it just doesn't work

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


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?

Paul_Hossler
12-13-2012, 06:25 PM
Try


Set ttt = CRange.Rows(2).EntireRow


Paul

Teeroy
12-13-2012, 10:47 PM
You don't really need ttt. You could simply use:
CRange.Rows(2).EntireRow.Insert
And CStore isn't used at all so you could get rid of it.