Consulting

Results 1 to 2 of 2

Thread: Fill Rows Based On Cell Above

  1. #1
    VBAX Regular
    Joined
    Jun 2012
    Posts
    20
    Location

    Fill Rows Based On Cell Above

    What I want to do is run a macro that will populate column A with the same thing that resides directly above it. Example in A1 I have the word Company AAA, A2:A6 are empty, and I would like the contents of A1 to fill - A2:A6 with same value in A1. A7 = Company BBB and A8:12 are empty. A8-A12 need to be filled with Company BBB. I need this to occur for everything in row A and the number of records in row A changes all the time. Any ideas on how to do this?

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    [VBA]Option Explicit

    Sub Fillin()

    Dim WS As Worksheet
    Dim LastRow As Long
    Dim aCell As Range
    Dim Temp$

    Set WS = ActiveWorkbook.Worksheets(1)

    With WS
    LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row

    For Each aCell In .Range("A1:A" & LastRow)
    If aCell.Value <> "" Then
    Temp$ = aCell.Value
    Else
    aCell.Value = Temp$
    End If
    Next
    End With
    End Sub
    [/VBA]

    David


Posting Permissions

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