PDA

View Full Version : [SOLVED] Need VBA Help!



Teatimedgg
09-27-2017, 04:38 PM
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!

Bob Phillips
09-28-2017, 12:07 AM
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

Teatimedgg
09-30-2017, 04:34 AM
perfect! Thank you so much!!

mdmackillop
09-30-2017, 05:09 AM
For the future, please use a meaningful, searchable title for your queries.