Thread: Fill down a row
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
GTVT06 GTVT06 is offline
external usenet poster
 
Posts: 141
Default Fill down a row

On Jan 16, 8:53*pm, Joanne wrote:
The code works so sweet - I love it!!

Thank you for the explanation. It is kind of confusing to know you are
filling 'down' by using .end(xlUp)

Joanne



GTVT06 wrote:
On Jan 16, 6:57 pm, Joanne wrote:
Thank you again for your help. You make my job easier with your
willingness and promptness in answering my sos
I want to understand the code so that I can better learn to use it
myself.


This code looks like it looks at the number of rows on the worksheet,
then reads each cell value. If the value is nothing, then it selects the
cell and copies something to it.


What I don't get is how does it know what to copy to the empty cells and
how does it know when to read a cell that is not empty and then start
copying that. I think I understand that no variable is needed because we
are simply copying what we found in the cell. Again though, how did we
find it!!??? I am so confused.


ActiveCell.End(xlUp).Copy cell
This is the line I don't understand well


Thank you
Joanne


GTVT06 wrote:
On Jan 16, 5:13 pm, Joanne wrote:
WinXP Pro MSOffice 2003 Pro


I have a spreadsheet with hundreds of rows and 15 columns


Col A holds Company name
Each Company can have any number of line items on the spreadsheet
Col A has the Company name in the company's first line item only, then
the rest of Col A is empty until the company name changes.


I need to get Company name in Col A on each and every line item for the
company. I know I need to read the Company Name, then recognize cells in
col A that are empty (up to a new company name), copy the company name
into those cells, proceed to the next cell and read the next company
name, recognize the empty cells for that company, copy the name there
and etc until I reach the end of the spreadsheet.


Could someone help me with this, or point me to an example somewhere so
I can help myself?


I sure appreciate your time and effort.
Thanks
Joanne


hello, try this:


Sub filldwn()
Dim cell As Range
'adjust the range below to fit your needs
For Each cell In Range("A1:A50")
If cell.Value = "" Then
cell.Select
ActiveCell.End(xlUp).Copy cell
End If
Next cell
End Sub- Hide quoted text -


- Show quoted text -


No problem, any time! heres a summary of what the code is doing:


'Setting the range to which cells will be searched and filled
For Each cell In Range("A1:A50")
'If a cell is blank in the above row then....
If cell.Value = "" Then
'Select it!
cell.Select
'With the "" cell selected, go up to the previous
'it's like using Ctrl Up. Then copy that cell and paste it
' to "cell" which is the blank cell that was selected
ActiveCell.End(xlUp).Copy cell
End If
'repeats the process for the next cell
Next cell- Hide quoted text -


- Show quoted text -


Glad I could help!
well .end(xlUp) is actually going up to get the value of the cell
above the "" cell it can use that value to assign it to the "" cell.
Sorry if I'm explaining it in a confusing way