PDA

View Full Version : Fill Rows Based On Cell Above



dpmaki
06-13-2012, 11:32 AM
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?

Tinbendr
06-13-2012, 12:31 PM
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