LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default passing targets between functions


Hi folks!

For some reason I am getting an error when attempting to do this.
Could anyone explain why?


Code:
--------------------
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal target As Range)
Dim pos As Range

clearAround (target)
If target.Text = "w" Then gotoEmpty
If target = "" Then target = "x"

End Sub

Function clearAround(ByVal target As Range)
With target
If .Offset(1, 0) = "x" Then .Offset(1, 0).ClearContents
If .Offset(-1, 0) = "x" Then .Offset(-1, 0).ClearContents
If .Offset(0, 1) = "x" Then .Offset(0, 1).ClearContents
If .Offset(0, -1) = "x" Then .Offset(0, -1).ClearContents
End With
End Function

Function gotoEmpty(ByVal target As Range)
If target.Offset(1, 0) = "" Then target.Offset(1, 0).Select
ElseIf target.Offset(-1, 0) = "" Then target.Offset(-1, 0).Select
ElseIf target.Offset(0, 1) = "" Then target.Offset(0, 1).Select
ElseIf target.Offset(0, -1) = "" Then target.Offset(0, -1).Select
Else: findEmpty = Cells(25, 25)
End If
End Function
--------------------


The error I get is on the "If target.Text = "w" Then gotoEmpty" line in
the _change sub. It tells me the argument is not optional. I'm not
sure what that means.

Any ideas? Thoughts?

Furthermore, how do you 'read' keystrokes or keypresses? I am trying
to build a maze game (mostly to learn more about excel vba) and would
love to be able to use the arrow keys instead of the _change function.

In the example above, the 'x' symbolizes where the player is. And 'w'
symbolizes where walls are. (Conditional Formatting will make this
much more graphical than it sounds)

Thanks guys!


--
ph8
------------------------------------------------------------------------
ph8's Profile: http://www.excelforum.com/member.php...o&userid=19871
View this thread: http://www.excelforum.com/showthread...hreadid=520051

 
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
passing arrays to user defined functions ramki Excel Worksheet Functions 2 February 15th 06 08:34 AM
General Question regarding passing cells, ranges, cell values through subs & functions [email protected] Excel Programming 1 September 5th 04 06:46 PM
passing arrays between functions in VBA Tom Ogilvy Excel Programming 3 March 1st 04 05:54 PM
Passing parameters between functions Gaston[_7_] Excel Programming 4 February 9th 04 04:08 AM
Passing Parameters to Userdefined Functions Peter M[_3_] Excel Programming 3 December 13th 03 07:56 PM


All times are GMT +1. The time now is 07:12 AM.

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"