View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ker_01 Ker_01 is offline
external usenet poster
 
Posts: 100
Default For...Each loop not working

Jayne-
You are checking to see if an entire range (Last_Cell) is Nothing. I'm
guessing you want to check each individual cell, and check them to see if
they are empty. Also, your exit for statement means that you would exit the
loop the first time you hit a cell that wasn't empty, whereas it sounds like
you want to skip empty cells and overwrite filled cells(?). Based on what I
think you said, maybe something like (aircode):

Dim IndividualCell as Excel.Worksheet.Cell
Dim WholeRange as Range

For Each IndividualCell In WholeRange
If IndividualCell.value <"" Then
IndividualCell.Activate
IndividualCell.Formula = "=dsum(H15:M2000,m15,ak5:al6)"
Else
'do nothing
End If
Next First_Cell

If I mixed up which cells get formulas and which get skipped, just change
the < to =

Aircode, so you may have to tweak the syntax.

HTH,
Keith


"Jayne22" wrote in message
...
I'm trying to fill in a formula for each empty cell in Last_Cell (a range
that i declared); if the cell is not empty, it can skip that cell. Why
doesn't this work when there are definitely empty cells in the range?

Dim First_Cell, Last_Cell as Range
For Each First_Cell In Last_Cell
If Last_Cell Is Nothing Then
First_Cell.Activate
ActiveCell.Formula = "=dsum(H15:M2000,m15,ak5:al6)"
Else
Exit For
End If
Next First_Cell

End Sub