Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Prefill column

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,393
Default Prefill column

This seems to work for me

Sub tryme()
mylast = Cells(Cells.Rows.Count, "B").End(xlUp).Row
mytext = Cells(1, "A")
For j = 2 To mylast
If Cells(j, "A") = "" Then
Cells(j, "A") = mytext
Else
mytext = Cells(j, "A")
End If
Next j
End Sub

Save file before trying it - just incase!
best wishes
--
Bernard Liengme
http://people.stfx.ca/bliengme
Microsoft Excel MVP

"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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Prefill column

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
chg chg is offline
external usenet poster
 
Posts: 15
Default Prefill column

What about that?

Sub FillBlanksColA()

Dim rng As Range
Dim rCell As Range
Set rng = Range(Cells(1, 1), Cells(1, 2).End(xlDown))

For Each rCell In rng
If rCell.Value = "" Then
rCell.Value = rCell.Offset(-1, 0).Value
End If
Next

End Sub
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Prefill column

try this
Option Explicit
Sub test()
Const WORKSHEET_NAME As String = "Sheet1"
Const WHATCOLUMN As String = "B"
Dim i As Long
Dim sString As String
i = 1
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets(WORKSHEET_NAME)

Dim rng As Range
Set rng = ws.Range(ws.Cells(2, WHATCOLUMN), ws.Cells(Rows.Count,
WHATCOLUMN).End(xlUp))

Dim Cell As Range
For Each Cell In rng
If Cell.Offset(0, -1).Value < "" Then
sString = Cell.Offset(0, -1).Value
Else
Cell.Offset(0, -1).Value = sString
End If
Next

End Sub

"SITCFanTN" wrote:

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell validation prefill Sue Excel Discussion (Misc queries) 2 April 9th 08 09:24 PM
Prefill a text box on a form Mike H. Excel Programming 2 August 17th 07 04:46 PM
How can I prefill a text field with leading 0s? Sweetetc Excel Worksheet Functions 4 February 24th 06 07:04 PM
Prefill cust info from drop list into other cells carris76 Excel Worksheet Functions 2 May 28th 05 07:28 PM
How do I convert dollars and cents to text, and prefill the cell . Jan Buckley Excel Worksheet Functions 1 January 20th 05 07:22 PM


All times are GMT +1. The time now is 06:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"