PDA

View Full Version : VBA code for inserting blank row in between the data points



shekar
11-03-2012, 08:12 AM
Hi All,

I have a huge excel which contains lot of data points , here i want to find the particular data point and above that i want to insert a blank row.....my data as follows

1 Sales Order
2 minute
3 Two
4 second
5 Three
6 Sales Order
7 minute
8 Two
9 second
10 Three
11 Sales Order
12 minute
13 Two
14 second
15 Three
16 Sales Order
17 minute
18 Two
19 second
20 Three

Here i want to find the "Sales order" and above that i want to insert a blank row....

xld
11-03-2012, 11:23 AM
Sub ProcessData()
Dim lastrow As Long
Dim i As Long

With ActiveSheet

lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = lastrow - 1 To 1 Step -1

If .Cells(i + 1, "B").Value = "Sales Order" Then

.Rows(i + 1).Insert
End If
Next i
End With
End Sub

shekar
11-03-2012, 09:50 PM
Sub ProcessData()
Dim lastrow As Long
Dim i As Long

With ActiveSheet

lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = lastrow - 1 To 1 Step -1

If .Cells(i + 1, "B").Value = "Sales Order" Then

.Rows(i + 1).Insert
End If
Next i
End With
End Sub