Insert Rows...Big Problem...

daniel50096230

Board Regular
Joined
May 2, 2008
Messages
163
I have a problem here...Firstly,I had fix my rows is from 1 to 100,and each ten rows consists as one row and I had use border to separate each ten rows.(Eg,row 1 to 10 is 1row).....So when I click a button and I choose to add 10rows after row 20,how can I do so?because when i choose to add 10rows after row 20,the existing row start from 21 will move down....But the problem is I had fix my rows to 100 only...How can I do so that the row 21 will move down and at the same time check the total of rows will not exceed 100?
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Code:
Private Sub CommandButton2_Click()
For i = 1 To 10
ActiveCell.EntireRow.Validation.Delete
ActiveSheet.Unprotect
ActiveCell.EntireRow.Locked = False
ActiveCell.EntireRow.Insert
Cells(ActiveCell.Row + 1, 10).Resize(1, 20).Copy _
Destination:=Cells(ActiveCell.Row, 10)
Cells(ActiveCell.Row, 8).Clear ' Column H
Cells(ActiveCell.Row, 11).Clear ' Column K
Cells(ActiveCell.Row, 13).Clear ' Column M
Next i
End Sub

After I click the button,my Excel is totally hang,anyone can tell me what is the problem???
 
Upvote 0
http://i145.photobucket.com/albums/r229/daniel50096230/Picture1.jpg

You may view through this website since I am not really understand how to post up the image in here...From the image there,you can see my data is start from row 23 to 24022.....If I would like to add 10 rows simultaneously after row 32,then all the data start from row 32 will move down....But at the moment,I need to check if the move down all the data,will it exceed 24022...If exceed,messagebox will be prompt and cancel the insert.
 
Upvote 0
Try this

Code:
Option Explicit

Sub InsertRow()
'Check extent of data
Dim Lastrow As Long
    Lastrow = Cells.Find(What:="*", _
              After:=[A1], SearchOrder:=xlByRows, _
              SearchDirection:=xlPrevious).Row
If Lastrow + 9 >= 24022 Then
    MsgBox ("Rows will exceed 24022!")
    Exit Sub
Else
'Insert 10 rows
Dim myRange As Range
Dim AnsRange1 As Integer
Dim AnsRange As Range
Set myRange = Application.InputBox(Prompt:="Select row to insert 10 rows below", Type:=8)
AnsRange1 = myRange.Row
Range(AnsRange1 & ":" & AnsRange1 + 9).Insert Shift:=xlDown

End If
End Sub
 
Upvote 0
It occur the following error after I type the row number:

"The reference you type is not valid,or you did not provide a reference where one was required.To enter a refenrece using mouse,click in the edit box,and then click the cell in the sheet you want to refer to, or drag to the range you want to select."
 
Upvote 0

Forum statistics

Threads
1,214,605
Messages
6,120,476
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top