Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
blazzae
 
Posts: n/a
Default Insert more than 1 Row Syntax


Hi all,

If the Syntax to insert 1 row is ( macro) :

Selection.EntireRow.Insert

Then what is the correct Syntax to insert more than 1 row ?
Let's say there were 5 rows.

I though it would be:

Selection.EntireRow.Insert,5)

Thankyou.


--
blazzae
------------------------------------------------------------------------
blazzae's Profile: http://www.excelforum.com/member.php...o&userid=24981
View this thread: http://www.excelforum.com/showthread...hreadid=385147

  #2   Report Post  
Max
 
Posts: n/a
Default

From tinkering around with the code produced by the macro recorder,
something like this seems to work:

Range("a1:a5").EntireRow.Insert

--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----
"blazzae" wrote in
message ...

Hi all,

If the Syntax to insert 1 row is ( macro) :

Selection.EntireRow.Insert

Then what is the correct Syntax to insert more than 1 row ?
Let's say there were 5 rows.

I though it would be:

Selection.EntireRow.Insert,5)

Thankyou.


--
blazzae
------------------------------------------------------------------------
blazzae's Profile:

http://www.excelforum.com/member.php...o&userid=24981
View this thread: http://www.excelforum.com/showthread...hreadid=385147



  #3   Report Post  
blazzae
 
Posts: n/a
Default


Thanks for reply.

It can't be from cell range

It does a Find with this code:

Sub FindWhat()

Cells.Find(What:="Here !", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate ' back to new position ready to paste

' inserts 5 rows
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert

End Sub

But I actualy need to add 30 Rows from the "Here !" location.

The location could be anywhere in sheet.


--
blazzae
------------------------------------------------------------------------
blazzae's Profile: http://www.excelforum.com/member.php...o&userid=24981
View this thread: http://www.excelforum.com/showthread...hreadid=385147

  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

How about...

Option Explicit
Sub FindWhat()

Dim FoundCell As Range
Dim NumberToInsert As Long

NumberToInsert = 30

With ActiveSheet

Set FoundCell = .Cells.Find(What:="Here !", _
After:=.Cells(.Cells.Count), LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

End With

If FoundCell Is Nothing Then
MsgBox "not found"
Else
FoundCell.Offset(1, 0).Resize(NumberToInsert).EntireRow.Insert
End If

End Sub

I did add it after the FoundCell (.offset(1,0) can be removed if you want).



blazzae wrote:

Thanks for reply.

It can't be from cell range

It does a Find with this code:

Sub FindWhat()

Cells.Find(What:="Here !", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate ' back to new position ready to paste

' inserts 5 rows
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert

End Sub

But I actualy need to add 30 Rows from the "Here !" location.

The location could be anywhere in sheet.

--
blazzae
------------------------------------------------------------------------
blazzae's Profile: http://www.excelforum.com/member.php...o&userid=24981
View this thread: http://www.excelforum.com/showthread...hreadid=385147


--

Dave Peterson
  #5   Report Post  
Max
 
Posts: n/a
Default

Thanks for the pick-up, Dave !
Tried out your sub, runs great.
The OP should be pleased ..
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----




  #6   Report Post  
blazzae
 
Posts: n/a
Default


Thanks,
I'll be replacing it with the 30 lines of code over the next few days
and see how it goes.

One I'll mess with is where it say's "show message box", it might turn
out to be a "what if" or "find next then" etc, but I have to try it as
a script first.
Will let you know

cheers


--
blazzae
------------------------------------------------------------------------
blazzae's Profile: http://www.excelforum.com/member.php...o&userid=24981
View this thread: http://www.excelforum.com/showthread...hreadid=385147

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simultaneouly insert of rows or col. - Ajit Ajit Munj Excel Discussion (Misc queries) 1 March 23rd 05 09:17 AM
insert picture BillGwyer Excel Discussion (Misc queries) 1 March 4th 05 06:37 PM
Insert Line Macro Spyder Excel Discussion (Misc queries) 1 March 3rd 05 12:17 AM
Challenging Charting C TO Charts and Charting in Excel 0 January 17th 05 06:57 PM
Function to automatically insert a new sheet as a result of data entry? Mark Mulik Excel Worksheet Functions 2 November 28th 04 02:21 AM


All times are GMT +1. The time now is 12:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"