Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
finding groups of empty cells in a column | Excel Programming | |||
Finding a empty / blank column | Excel Programming | |||
finding the next empty column | Excel Programming | |||
Finding Next Empty Cell in Column | Excel Programming | |||
Finding last non-empty column in row... | Excel Programming |