Thread: Prefill column
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Prefill column

I guess I should point out why I said my solution "should be pretty
speedy"... the difference between my loop and the others that have been
posted so far is the number of iterations that will be performed. For your
posted example data, the macro I posted will iterate 3 times (once for each
blank area) whereas the other solution's loops will iterate 9 times (once
per cell). I would also note that my calculation for the LastRow does not
require you to know in advance which column will contain the row with the
last piece of data in it... my code finds the last filled row of data no
matter what column it is in.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
This macro should be pretty speedy...

Sub FillInTheBlanks()
Dim Area As Range, LastRow As Long
Const ColLetter As String = "A"
On Error Resume Next
LastRow = Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
For Each Area In Columns(ColLetter)(1).Resize(LastRow). _
SpecialCells(xlCellTypeBlanks).Areas
Area.Value = Area(1).Offset(-1).Value
Next
End Sub

--
Rick (MVP - Excel)


"SITCFanTN" wrote in message
...
Below is a sample of the data I download to a spreadsheet. I need to
write a
macro to fill in the empty cells in column A with the data from the
previous
cell in the column with data. I know I didn't explain that well but in
the
example below, I need TF48 to fill in Col A for rows 3,4 & 5. Then T16A
would fill in row 7 and T505 in row 9 and 10. I hope I've explained this
sufficiently. Thanks in advance for your help.

1 A B C D
2 TF48 $100.00 ABC 20091116
3 $ 50.00 DTR 20091116
4 $ 25.00 PLO 20091116
5 $ 75.00 FRD 20091116
6 T16A $100.35 UYE 20091116
7 $124.55 PLE 20091116
8 T505 $109.00 REW 20091115
9 $876.90 JLO 20091113
10 $234.90 REW 20091116