ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Insert a Row (https://www.excelbanter.com/excel-programming/299560-insert-row.html)

Matt B

Insert a Row
 
Hi,

Somewhere in column A, a cell contains the text "sales". Within a
macro I want to insert 3 rows above the row that has "sales" in it.

Is this possible?

TIA

Matt

Frank Kabel

Insert a Row
 
Hi
try the following macro.
Sub insert_rows()
Dim lastrow As Long
Dim row_index As Long

lastrow = ActiveSheet.Cells(Rows.count, "A").End(xlUp).row
For row_index = lastrow - 1 To 1 Step -1
If lcase(Cells(row_index+1, "A").Value) ="sales" Then
Cells(row_index + 1, "A").resize(3,1).EntireRow.Insert _
(xlShiftDown)
End If
Next
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany

"Matt B" schrieb im Newsbeitrag
m...
Hi,

Somewhere in column A, a cell contains the text "sales". Within a
macro I want to insert 3 rows above the row that has "sales" in it.

Is this possible?

TIA

Matt



JE McGimpsey

Insert a Row
 
One way:

Public Sub InsertAboveSales()
Dim rFound As Range
Set rFound = Columns(1).Find( _
What:="sales", _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Not rFound Is Nothing Then _
rFound.Resize(3, 1).EntireRow.Insert
End Sub


In article ,
(Matt B) wrote:

Hi,

Somewhere in column A, a cell contains the text "sales". Within a
macro I want to insert 3 rows above the row that has "sales" in it.

Is this possible?

TIA

Matt



All times are GMT +1. The time now is 06:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com