Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Testing for contiguous cells

For a game, I need to determine whether non-blank cells in range
A1:J10 are orthogonally contiguous. If I had values in cells A1, A2,
A3, B3 and C3 then the result would be true. However, remove the value
from cell A3 and the result is now false. Any ideas how to do this
test?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Testing for contiguous cells

if intersect(Range("A1").End(xldown).End(xltoRight),R ange("A1:J10")) is
nothing then
if intersect(Range("A1").End(xltoRight).End(xldown),R ange("A1:J10)) is
nothing then
msgbox "Not orthogonally contiguous"
end if
End if

of
if isemtpy(Range("A1").End(xldown).offset(0,1)) then
if isempty(Range("A1").End(xltoRight).Offset(1,0)) Then
msgbox "Not orthogonally contiguous"
end if
End if

--
Regards,
Tom Ogilvy

"jamieuk" wrote in message
om...
For a game, I need to determine whether non-blank cells in range
A1:J10 are orthogonally contiguous. If I had values in cells A1, A2,
A3, B3 and C3 then the result would be true. However, remove the value
from cell A3 and the result is now false. Any ideas how to do this
test?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Testing for contiguous cells

Thanks Tom, I appreciate you taking the time to reply. Unfortunately,
I couldn't get either of your suggestions to work.

I took your second suggestion, because it takes account of range
A1:J10 (the 'board'). I need to test that every non-blank cell is
contiguous with all others (not just cell A1), so I put the code in a
loop:

Sub Test()

Dim oBoard As Excel.Range
Dim oSqaure As Excel.Range
Dim blnContiguous As Boolean

Set oBoard = Range("A1:J10")

blnContiguous = True

For Each oSqaure In oBoard
If Len(oSqaure.Value) 0 Then
blnContiguous = IsContiguous(oSqaure, oBoard)
If Not blnContiguous Then
Exit For
End If
End If
Next

If Not blnContiguous Then
MsgBox "Not orthogonally contiguous"
End If

End Sub

Function IsContiguous(ByVal Square As Excel.Range, _
ByVal Board As Excel.Range) As Boolean

IsContiguous = True

If Intersect(Square.End(xlDown).End(xlToRight), Board) Is Nothing Then
If Intersect(Square.End(xlToRight).End(xlDown), Board) Is Nothing
Then
IsContiguous = False
End If
End If

End Function

When there are non-blank values in A1 and A2 only (obviously
contiguous), both combinations of xlDown and xlRight (for both cells)
end up off the board and IsContiguous incorrectly returns false.

An approach seems to be emerging i.e. count the cell immediately to
the left or below the current cell but also take account of whether
the current cell has already been counted. But it's making my head
hurt!

Any further suggestions would be most welcome.

--

"Tom Ogilvy" wrote in message ...
if intersect(Range("A1").End(xldown).End(xltoRight),R ange("A1:J10")) is
nothing then
if intersect(Range("A1").End(xltoRight).End(xldown),R ange("A1:J10)) is
nothing then
msgbox "Not orthogonally contiguous"
end if
End if

of
if isemtpy(Range("A1").End(xldown).offset(0,1)) then
if isempty(Range("A1").End(xltoRight).Offset(1,0)) Then
msgbox "Not orthogonally contiguous"
end if
End if

--
Regards,
Tom Ogilvy

"jamieuk" wrote in message
om...
For a game, I need to determine whether non-blank cells in range
A1:J10 are orthogonally contiguous. If I had values in cells A1, A2,
A3, B3 and C3 then the result would be true. However, remove the value
from cell A3 and the result is now false. Any ideas how to do this
test?

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
Non-contiguous cells Kokomojo Excel Discussion (Misc queries) 2 November 6th 07 04:09 PM
Testing Cells Paul New Users to Excel 6 June 8th 07 07:14 PM
TESTING A RANGE OF CELLS Richard[_2_] New Users to Excel 3 April 1st 07 02:52 PM
TESTING A RANGE OF CELLS Richard[_2_] Excel Worksheet Functions 3 April 1st 07 02:52 PM
testing for non-empty cells Paul James[_2_] Excel Programming 6 August 3rd 03 09:04 AM


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