B
bpascal123
Hi,
I'd like to copy the format and more importantly the formulae of the
last row and to insert it as a new row in the last of the current
range.
A1 contains a number in blue
B1 contains a date
C1 has a vlookup formulae based on the value in F1
D1 same as C1
E1 same as D1
F1 contains a number used as a reference for the C1, D1, E1 vlookup
formula
G1 contains a number
H1 contains a number
i1 contains the result of the product of G1 and H1
The sheet is protected, range C:F and i1 is locked.
As I can't insert a new row on a protected sheet, I have this workbook
macro :
Private Sub Workbook_Open()
With Worksheets("Sheet1")
.Protect "sos", UserInterfaceOnly:=True
End With
End Sub
The following macro does the job but it can be made shorter and look
more like usual vba code.
Sub InsertRows()
Dim i, lastrow As Long
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
Rows(lastrow + 1).Insert
Rows(lastrow).Copy Destination:=Rows(lastrow + 1)
For i = 1 To 9
Cells(lastrow + 1, i).Value = ""
Next i
For i = 1 To 9
Cells(lastrow + 1, i).Formula = Cells(lastrow, i).Formula
Next i
Cells(lastrow + 1, "a").Value = ""
Cells(lastrow + 1, "b").Value = ""
Cells(lastrow, "C").Copy Destination:=Cells(lastrow + 1, "C")
Cells(lastrow, "D").Copy Destination:=Cells(lastrow + 1, "D")
Cells(lastrow, "E").Copy Destination:=Cells(lastrow + 1, "E")
Cells(lastrow + 1, "f").Value = ""
Cells(lastrow + 1, "g").Value = ""
Cells(lastrow + 1, "h").Value = ""
Cells(lastrow, "i").Copy Destination:=Cells(lastrow + 1, "i")
End Sub
Any suggestion?
Pascal
I'd like to copy the format and more importantly the formulae of the
last row and to insert it as a new row in the last of the current
range.
A1 contains a number in blue
B1 contains a date
C1 has a vlookup formulae based on the value in F1
D1 same as C1
E1 same as D1
F1 contains a number used as a reference for the C1, D1, E1 vlookup
formula
G1 contains a number
H1 contains a number
i1 contains the result of the product of G1 and H1
The sheet is protected, range C:F and i1 is locked.
As I can't insert a new row on a protected sheet, I have this workbook
macro :
Private Sub Workbook_Open()
With Worksheets("Sheet1")
.Protect "sos", UserInterfaceOnly:=True
End With
End Sub
The following macro does the job but it can be made shorter and look
more like usual vba code.
Sub InsertRows()
Dim i, lastrow As Long
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
Rows(lastrow + 1).Insert
Rows(lastrow).Copy Destination:=Rows(lastrow + 1)
For i = 1 To 9
Cells(lastrow + 1, i).Value = ""
Next i
For i = 1 To 9
Cells(lastrow + 1, i).Formula = Cells(lastrow, i).Formula
Next i
Cells(lastrow + 1, "a").Value = ""
Cells(lastrow + 1, "b").Value = ""
Cells(lastrow, "C").Copy Destination:=Cells(lastrow + 1, "C")
Cells(lastrow, "D").Copy Destination:=Cells(lastrow + 1, "D")
Cells(lastrow, "E").Copy Destination:=Cells(lastrow + 1, "E")
Cells(lastrow + 1, "f").Value = ""
Cells(lastrow + 1, "g").Value = ""
Cells(lastrow + 1, "h").Value = ""
Cells(lastrow, "i").Copy Destination:=Cells(lastrow + 1, "i")
End Sub
Any suggestion?
Pascal