Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Ivan
 
Posts: n/a
Default macro for autofilling cells below identically

I need to sort a list by column "A" to take out blank rows and/or rows that
are populated with garbage that tagged along when I imported it as text.
Here is the problem (simplified for easier explanation):

Cell A1 is a part number.
Cells A2:A5 are empty
Cells B1:B5 are inventory counts of A1

This pattern repeats itself and the list is too long to manually copy Cell
A1 down to A2:A5.
Of course if I sort as it is, all the rows where A2:A5 are blank will sort
to the bottom.

How can I fill all empty cells with the value immediately above it?


  #2   Report Post  
Posted to microsoft.public.excel.misc
Greg Wilson
 
Posts: n/a
Default macro for autofilling cells below identically

Test on a copy of your data. This sort of thing should be rigorously tested
on duplicate data before put into use. The code will operate on the active
worksheet and will likely screw up data if run with the wrong sheet active.
Can be hard coded to work on a specified sheet:

Sub FillEmptyCells()
Dim r As Range, c As Range
Dim txt As String

Set r = Range(Cells(1, 2), Cells(Rows.Count, 2).End(xlUp))
Set r = r.Offset(0, -1)
r.Select
Exit Sub
For Each c In r.Cells
If IsEmpty(c) Then
c.Value = txt
Else
txt = c.Value
End If
Next
End Sub

Regards,
Greg


"Ivan" wrote:

I need to sort a list by column "A" to take out blank rows and/or rows that
are populated with garbage that tagged along when I imported it as text.
Here is the problem (simplified for easier explanation):

Cell A1 is a part number.
Cells A2:A5 are empty
Cells B1:B5 are inventory counts of A1

This pattern repeats itself and the list is too long to manually copy Cell
A1 down to A2:A5.
Of course if I sort as it is, all the rows where A2:A5 are blank will sort
to the bottom.

How can I fill all empty cells with the value immediately above it?



  #3   Report Post  
Posted to microsoft.public.excel.misc
Greg Wilson
 
Posts: n/a
Default macro for autofilling cells below identically

Take out the:

r.Select
Exit Sub

Testing leftovers. Sorry for the oversight.

Greg

"Greg Wilson" wrote:

Test on a copy of your data. This sort of thing should be rigorously tested
on duplicate data before put into use. The code will operate on the active
worksheet and will likely screw up data if run with the wrong sheet active.
Can be hard coded to work on a specified sheet:

Sub FillEmptyCells()
Dim r As Range, c As Range
Dim txt As String

Set r = Range(Cells(1, 2), Cells(Rows.Count, 2).End(xlUp))
Set r = r.Offset(0, -1)
r.Select
Exit Sub
For Each c In r.Cells
If IsEmpty(c) Then
c.Value = txt
Else
txt = c.Value
End If
Next
End Sub

Regards,
Greg


"Ivan" wrote:

I need to sort a list by column "A" to take out blank rows and/or rows that
are populated with garbage that tagged along when I imported it as text.
Here is the problem (simplified for easier explanation):

Cell A1 is a part number.
Cells A2:A5 are empty
Cells B1:B5 are inventory counts of A1

This pattern repeats itself and the list is too long to manually copy Cell
A1 down to A2:A5.
Of course if I sort as it is, all the rows where A2:A5 are blank will sort
to the bottom.

How can I fill all empty cells with the value immediately above it?



  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default macro for autofilling cells below identically

You have more replies at your post in .excel

Ivan wrote:

I need to sort a list by column "A" to take out blank rows and/or rows that
are populated with garbage that tagged along when I imported it as text.
Here is the problem (simplified for easier explanation):

Cell A1 is a part number.
Cells A2:A5 are empty
Cells B1:B5 are inventory counts of A1

This pattern repeats itself and the list is too long to manually copy Cell
A1 down to A2:A5.
Of course if I sort as it is, all the rows where A2:A5 are blank will sort
to the bottom.

How can I fill all empty cells with the value immediately above it?


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
John James
 
Posts: n/a
Default macro for autofilling cells below identically


If you want to do it without a macro, try entering this formula in C1
and copying down:
=OFFSET(A1,-MOD(ROW()+4,5),0)


--
John James
------------------------------------------------------------------------
John James's Profile: http://www.excelforum.com/member.php...o&userid=32690
View this thread: http://www.excelforum.com/showthread...hreadid=531279

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
Cells turn 'hot' and execute distant macro button Kevryl Excel Discussion (Misc queries) 1 March 31st 06 02:08 PM
Can't copy & paste - "merged cells must be identically sized" Rayo K Excel Discussion (Misc queries) 2 March 14th 06 12:19 AM
Macro to copy cells to rows below [email protected] Excel Discussion (Misc queries) 1 January 20th 06 06:59 PM
checking that cells have a value before the workbook will close kcdonaldson Excel Worksheet Functions 8 December 5th 05 04:57 PM
identically size merged cells for sorting rows julieanne12 Excel Discussion (Misc queries) 1 August 24th 05 11:26 AM


All times are GMT +1. The time now is 03:30 PM.

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

About Us

"It's about Microsoft Excel"