views:

129

answers:

1

I want to insert a list (below: generator, control tower, etc.) repeatedly throughout a spreadsheet. It should be inserted every other row (after each Turbine) and offset one column as shown below. I don't know how to write a macro to do this automatically. Any help is appreciated.

TURBINE A-2
    Generator
    Control Tower
    Brakes
    Pitch System
    Hydraulic System
    Cooling System
    Oil Filtration System
    Lighting System
    Ascent System
    Scada Systems
    Nacelle Cover
    Cable System
    Fire System
    Blades
TURBINE A-3 
    Generator
    Control Tower
    Brakes
    Pitch System
    Hydraulic System
    Cooling System
    Oil Filtration System
    Lighting System
    Ascent System
    Scada Systems
    Nacelle Cover
    Cable System
    Fire System
    Blades
TURBINE A-4 
TURBINE A-5 
TURBINE A-6 
TURBINE A-7
A: 

This should do the trick:

Public Sub AddEntries()
    Dim InsertionRange As Range
    Dim HeaderRow As Integer
    Dim RowIndex As Integer

    Const ListSize = 14
    Dim ListEntries(1 To ListSize) As String
    ListEntries(1) = "Generator"
    ListEntries(2) = "Control Tower"
    ListEntries(3) = "Brakes"
    ListEntries(4) = "Pitch System"
    ListEntries(5) = "Hydraulic System"
    ListEntries(6) = "Cooling System"
    ListEntries(7) = "Oil Filtration System"
    ListEntries(8) = "Lighting System"
    ListEntries(9) = "Ascent System"
    ListEntries(10) = "Scada Systems"
    ListEntries(11) = "Nacelle Cover"
    ListEntries(12) = "Cable System"
    ListEntries(13) = "Fire System"
    ListEntries(14) = "Blades"

    HeaderRow = 1
    While (Cells(HeaderRow, 1).Value <> "")
        Rows(Trim$(Str$(HeaderRow + 1)) & ":" & Trim$(Str$(HeaderRow + ListSize))).Insert shift:=xlDown

        For RowIndex = 1 To ListSize
            Cells(RowIndex + HeaderRow, 2).Value = ListEntries(RowIndex)
        Next RowIndex

        HeaderRow = HeaderRow + ListSize + 1
    Wend
End Sub

I'm assuming that the TURBINE entries are all in the first column of the excel file.

e.James