Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default finding groups of empty cells in a column

Here is another approach. This macro will fill in each blank cell with the
value of the first non-blank cell below it. Then you can get subtotals using
Data Subtotals, SUMIF formulas, a pivot table, etc.

Sub FillBlanks()
'Define variables
Dim TotRng As Range, LastRow As Long
Const MyCol = 2 'column number to check
'Find the last used cell on the sheet, and select a range
'in the specified column from row 1 through the last row
LastRow = Cells(Rows.Count, MyCol).End(xlUp).Row
Range(Cells(1, MyCol), Cells(LastRow, MyCol)).Select
Set TotRng = Selection
On Error GoTo NoBlanks
'Put a formula in every blank cell pulling the value
'from the cell below it.
With TotRng
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[1]C"
End With
Calculate
'Convert the formulas to values.
With ActiveCell.CurrentRegion
.Cells.Value = Cells.Value
End With
NoBlanks:
Set TotRng = Nothing
End Sub

Hutch

"Steve" wrote:

Thanks for the reply Tom, but the reason I need to do it 1 group at a
time is so I can subtotal the adjacent cells in another column for
each group of empty cells I find (plus 1). I would then place that
subtotal in another column.

For example:

Col A ColB Col C
1.6
1.5
2.7 2/1/2009 5.8
5.5
6.8
4.3 2/2/2009 16.6

---
Steve


On Jan 30, 12:25 pm, Tom Hutchins
wrote:
I'm not sure why you need to find the empty cells in groups. It sounds like
you just want to find all the empty cells within the used range for a
particular column. The following code will do that:

Sub CheckBlanx()
Dim rng As Range, LastRow As Long
Const MyCol = 1 'column number to process
LastRow = Cells(Rows.Count, MyCol).End(xlUp).Row
Range(Cells(1, MyCol), Cells(LastRow, MyCol)).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
For Each rng In Selection
'do something with adjacent column
Next rng
End Sub

Hope this helps,

Hutch

"Steve" wrote:
I am having trouble constructing code which will find groups of empty
cells in a column. The empty cells (all the empty cells do not have
any data or formulas in them) are broken by scattered cells containing
data. I need to be able to isolate a group of empty cells, perform
some calculations on the adjacent cells in the adjacent column, then
isolate the next group of empty cells, do some more calculations on
the adjacent cells in the adjacent column, and so on, all the way to
the last cell containing data in that column.


Thanks in advance for any assistance...


---
Steve



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
finding groups of empty cells in a column Tom Hutchins Excel Programming 0 February 2nd 09 05:34 PM
Finding a empty / blank column ogopogo5 Excel Programming 2 October 29th 08 07:52 PM
finding the next empty column Peter Excel Programming 9 September 24th 08 11:57 AM
Finding Next Empty Cell in Column caldog Excel Programming 4 February 3rd 06 02:41 PM
Finding last non-empty column in row... Mika[_3_] Excel Programming 2 November 11th 03 08:50 PM


All times are GMT +1. The time now is 12:30 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"