Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Empty cells in For Loop

I am trying to write a For Loop which runs all the populated cells in the
range through a calculation. My question is how do I make sure that empty or
null cells aren't selected to be used in the calculation? Essentially I just
want to ignore the empty/null cells. Below is the code for the loop in case
this helps:

For Each A In range1
For Each B In range1
If B.Value < A.Value Then
If Abs(A - B) <= testvalue Then
Sheets("Test Results").Select
range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Selection.Value = "Interference"
ActiveCell.Offset(0, 1).Select
Selection.Value = A.Value
ActiveCell.Offset(0, 1).Select
Selection.Value = B.Value
End If
End If
Next
Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Empty cells in For Loop

Do you mean that if a cell is empty then you don't care about the rest, that
is if an A is empty, you ignore that and all associated B's?

If so

For Each A In range1
If Len(A.Value) 0 Then
For Each B In range1
If Len(B.Value) 0 Then
If B.Value < A.Value Then
If Abs(A.Value - B.Value) <= testvalue Then
With Sheets("Test
Results").Range("A1").End(xlDown)
.Offset(1, 0).Value = "Interference"
.Offset(0, 1).Value = A.Value
.Offset(0, 1).Value = B.Value
End With
End If
End If
End If
Next B
End If
Next A


--
HTH

Bob Phillips

"Linking to specific cells in pivot table"
crosoft.com wrote in
message ...
I am trying to write a For Loop which runs all the populated cells in the
range through a calculation. My question is how do I make sure that empty

or
null cells aren't selected to be used in the calculation? Essentially I

just
want to ignore the empty/null cells. Below is the code for the loop in

case
this helps:

For Each A In range1
For Each B In range1
If B.Value < A.Value Then
If Abs(A - B) <= testvalue Then
Sheets("Test Results").Select
range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Selection.Value = "Interference"
ActiveCell.Offset(0, 1).Select
Selection.Value = A.Value
ActiveCell.Offset(0, 1).Select
Selection.Value = B.Value
End If
End If
Next
Next



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Empty cells in For Loop

Try the following approach. Note the major "Union" line added.
Also, a "Range" variable called "tmp" is added.

The macro minimize the scope to only those cells in the range with either
value or formula. All empty cells are ignored. Therefore, processing time
will be minimized.



Dim range1 As Range
Dim tmp As Range
Dim A As Object, B As Object
Dim testvalue

With range1
Set tmp = Union(.SpecialCells(2), .SpecialCells(-4123))
End With
For Each A In tmp
For Each B In tmp
If B.Value < A.Value Then
If IsNumeric(A) And IsNumeric(B) Then
If Abs(A - B) <= testvalue Then
With Worksheets("Test Results").Range("A1")
.End(xlDown).Offset(1, 0).Value = "Interference"
.End(xlDown).Offset(0, 1).Value = A.Value
.End(xlDown).Offset(0, 2).Value = B.Value
End With
End If
End If
End If
Next
Next


Regards,
Edwin Tam

http://www.vonixx.com



"Linking to specific cells in pivot table" wrote:

I am trying to write a For Loop which runs all the populated cells in the
range through a calculation. My question is how do I make sure that empty or
null cells aren't selected to be used in the calculation? Essentially I just
want to ignore the empty/null cells. Below is the code for the loop in case
this helps:

For Each A In range1
For Each B In range1
If B.Value < A.Value Then
If Abs(A - B) <= testvalue Then
Sheets("Test Results").Select
range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Selection.Value = "Interference"
ActiveCell.Offset(0, 1).Select
Selection.Value = A.Value
ActiveCell.Offset(0, 1).Select
Selection.Value = B.Value
End If
End If
Next
Next

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
Excel - Autom. Filter "Empty / Non Empty cells" should come first Rom Excel Discussion (Misc queries) 0 August 10th 05 04:32 PM
When I SUM cells & 1 is empty I need the result to be empty not 0 Maribel Excel Discussion (Misc queries) 1 August 2nd 05 12:49 AM
How can I convert empty strings to empty cells? Shane Excel Discussion (Misc queries) 2 July 19th 05 12:10 PM
Help - loop through cells in a range that are not together (several different cells as Target) Marie J-son[_5_] Excel Programming 4 April 3rd 05 09:54 PM
Can blank cells created using empty Double-Quotes not be empty?? JohnI in Brisbane Excel Programming 6 September 7th 03 11:22 PM


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