Consulting

Results 1 to 4 of 4

Thread: Need VBA Help!

  1. #1

    Question 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!
    Last edited by Teatimedgg; 09-27-2017 at 04:46 PM. Reason: forgot to add something

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    perfect! Thank you so much!!

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    For the future, please use a meaningful, searchable title for your queries.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •