I have a random list on column "A". What I would like to do is to insert a row if value below "Bills Payment" is "Payment code". Result sample is in Column "C" ut I would like it in Column A.
Book2 | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | Bills Payment: | Bills Payment: | |||
2 | Payment Code: 748494 | ||||
3 | Butter | Payment Code: 748494 | |||
4 | Gardenia | Butter | |||
5 | 600 | Gardenia | |||
6 | Bread | 600 | |||
7 | Butter | Bread | |||
8 | Cookies | Butter | |||
9 | Bills Payment: | Cookies | |||
10 | Payment Code: 89721 | Bills Payment: | |||
11 | 700 | ||||
12 | 500 | Payment Code: 89721 | |||
13 | Tasty | 700 | |||
14 | Gardenia | 500 | |||
15 | Butter | Tasty | |||
16 | Bills Payment: | Gardenia | |||
17 | Lay info: 124364 | Butter | |||
18 | Payment Code: 89721 | Bills Payment: | |||
19 | 700 | Lay info: 124364 | |||
20 | 800 | Payment Code: 89721 | |||
21 | Absolute | 700 | |||
22 | Enfamil | 800 | |||
23 | Absolute | ||||
24 | Enfamil | ||||
Sheet1 |
VBA Code:
Sub Click()
Dim Sh As Worksheet
Dim currentValue As String
Dim previousValue As String
Set Sh = Sheets("Sheet2")
With Sh
'For each cell in the column
For i = 1 To .Cells(.Rows.Count, A).End(xlUp).Row
currentValue = "Bills Payment:"
previousValue = .Range(yourColumn & i).Offset(2, 0).Value
If previousValue = "Payment code:*" Then
.Rows(i).EntireRow.Insert Shift:=xlDown
End If
Next i
End With
End Sub