-
Need VBA Help!
Hey Everyone,
Newby here! I have a multiple columns of data but i want to insert a header line (1st line -range A2.H2) when the word Dog-A changes in Column C i want this to continue until the end of data in column c
Example:
H |
ABC company |
Header |
12345 |
123 |
12345 |
0 |
12 |
L |
ABC company |
Dog |
***x |
Unit |
1 |
|
|
L |
ABC company |
Dog |
***x |
Unit |
1 |
19.03 |
|
L |
ABC company |
Dog-A |
***x |
Unit |
1 |
200 |
|
L |
ABC company |
Cat |
***x |
Unit |
1 |
70 |
|
L |
ABC company |
Cat |
***x |
Unit |
1 |
15000 |
|
Any help would be appreciated!!! Thank you!
-
Code:
Sub AddHeaders()
Dim lastrow As Long
Dim i As Long
Application.ScreenUpdating = False
With ActiveSheet
lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row
For i = lastrow - 1 To 2 Step -1
If .Cells(i, "C").Value <> .Cells(i + 1, "C").Value Then
.Rows(i + 1).Insert
.Cells(i + 1, "A").Resize(, 8).Value = Array("H", "ABC company", "Header", "12345", "123", "12345", "0", "12")
End If
Next i
End With
Application.ScreenUpdating = True
End Sub
-
perfect! Thank you so much!!
-
For the future, please use a meaningful, searchable title for your queries.