Inserting a pre-formatted row


Posted by Hock-doong on December 08, 2000 10:38 PM

Hello,

Thank you all very much for your response which has helped me tremendously. best of all, they all worked. I must now bother you all once again with my problem. I would like to insert rows based on a number in a cell that I will type in, say cell G7.

The function that I hope to create is that when the user keys in a number, say 5, in cell G7, 5 rows will be created after the 10th row. However, these rows are not blank rows but rows that I have pre-formatted.

Q1. Could I hide a pre-formatted row?
Q2. can I write a Macro that will do the above and retrieve the format from the hidden row?

I've read an earlier post on inserting rows (but noe a pre-formatted row) and tried to use the code but an error occured.

Could anyone please help and guide?

Thank you very much in advance.

Best regards,
Hock-doong.

Posted by Ivan Moala on December 09, 2000 11:54 AM

YES, you can do this....What code did you use that
gave you errors ??

Ivan

Posted by Hock-doong on December 09, 2000 8:47 PM

****

Dear Ivan,

A question was raised sometime ago about inserting rows. The question was:

Could N rows be inserted automatically (say from 10th row) once value in
Cell (1,1) is changed to N ?

and the reply was:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then If IsNumeric(Target) Then
Rows(10).Resize(Target.Value).Insert
End Sub

another reply:

Put this in the worksheet change event


If Target.Address = "$A$3" Then
Rows("10:" & 10 + Target.Value).Select
Selection.Insert Shift:=xlDown
End If


The for both, my VBE shows the error occurs in the line:

If Target.Address = "$A$3"

even if I changed the reference cell to "$G$7", the cell that contain the variable.

The above also could not retrieve a pre-formatted row. It just inserts a blank row, right?

Thank you very much for your help.

Best regards,
Hock-doong.


Posted by Ivan Moala on December 09, 2000 10:56 PM

I think the code could have read;

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" And IsNumeric(Target) Then
Rows(10).Resize(Target.Value).Insert
'put code here to format
'the resized area
End If
End Sub


Then under the resize code put code to format
your area.

Ivan

Posted by Hock-doong on December 11, 2000 12:13 AM

Dear ivan,

Forgive my ignorance but where do I put the code?

Also how do I program the format or should I point it to a hidden pre-formatted row?

Thank ou very much for your help.

Best regards,
Hock-doong.

Posted by Ivan Moala on December 11, 2000 12:39 AM

The code should go in the worksheet module
Right click on the sheet tab and select view code.
Place the code here.

To get the format code then try using the macro recorder and formating how you want it to look.
Turn it of and look @ the code.....this is where
you will have to make the code more generic to
suit the range you want.........post the formating
code if unsure of how todo this or email me.


Ivan



Posted by Hock-doong on December 11, 2000 1:48 AM


**

Dear Ivan,

Thank you very much for your help. I'll paste my code here:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" And IsNumeric(Target) Then
Rows(10).Resize(Target.Value).Insert


'
' addrows Macro
' Macro recorded 12/11/00 by HO
'

'
Columns("A:A").Select
Selection.ColumnWidth = 0.92
Columns("B:B").Select
Selection.ColumnWidth = 8.43
Columns("C:C").Select
Selection.ColumnWidth = 8.43
Columns("D:D").Select
Selection.ColumnWidth = 10.14
Columns("E:E").Select
Selection.ColumnWidth = 6.86
Columns("F:F").Select
Selection.ColumnWidth = 0.92
Columns("G:G").Select
Selection.ColumnWidth = 9.57
Columns("H:H").Select
Selection.ColumnWidth = 9.57
Columns("I:N").Select
Selection.ColumnWidth = 9.57
ActiveWindow.ScrollColumn = 1
Range("B12:N12").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Range("B12").Select
With Selection.Interior
.ColorIndex = 10
.Pattern = xlSolid
End With
Selection.Font.ColorIndex = 2
Range("C12:N12").Select
With Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
End With
Selection.Font.ColorIndex = 0
Range("C12:F12").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.ShrinkToFit = False
.MergeCells = True
End With
End If
End Sub


However, when I run the macro, I got stuck with at the line:

.LineStyle = xlContinuous

and could not proceed.

Could you please help?

Thank you very much in advance.

Best regards,
Hock-doong.