Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Pass variables to Worksheet_SelectionChange

I have the following code which works well as it stands. My problem is that
I need to vary the range depending on conditions set in other code.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'----- ENABLE TICKS IN RELEVANT BOXES -----
Application.EnableEvents = False
On Error GoTo sub_exit
If Not Intersect(Target, Worksheets("Room").Range("P11:T39")) Is Nothing
Then
With Target
If .Value = Chr(252) Then
.Value = ""
Else
.Value = Chr(252)
.Font.Name = "Wingdings"
End If
End With
End If
sub_exit:
Application.EnableEvents = True
End Sub


I've tried changing the first line to Private Sub
Worksheet_SelectionChange(ByVal Target As Range, r, c) to pass row and
column but this causes a problem earlier in my code with an apparently
unrelated instruction.

To explain further, I have a form which the enables the user to select from
a number of lists using comboboxes. Once the comboboxes are populated, the
user presses a commandbutton.

Private Sub CommandButton1_Click()
With Worksheets("Room")
.Unprotect
.Range("F3") = ComboBox1.Text
.Range("W3") = ComboBox2.Text
.Range("I2") = CDate(TextBox1.Value)
.Visible = True
.Activate
.Range("A1").Select
.Protect
End With
Worksheets("Lookup").Visible = False
UserForm1.Hide
Call Worksheets("Room").UserForm_Reaction
With ActiveWindow
.WindowState = xlMaximized
End With
Worksheets("Room").Range("F2").Select
End Sub

The line causing the problem is .Unprotect but the code runs perfectly with
the original Worksheet_SelectionChange line.

Perhaps I'm expecting the impossible in trying to make the target range
dynamic.

Any ideas?

--
Ian
--


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Pass variables to Worksheet_SelectionChange


A worksheet change will only acccept Target as a parameter. You can
either use a cell in the worksheet as a parameter to the function or a
named range.

To get the uprotect to work you need to specify the activesheet

Activesheet.unprotect


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=158380

Microsoft Office Help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Pass variables to Worksheet_SelectionChange

Thanks Joel. The named range option looks promising, though I only need to
the code apply to part of a named range (ignoring the top 4 rows and the
left column). I may need to introduce another named range.

--
Ian
--

"joel" wrote in message
...

A worksheet change will only acccept Target as a parameter. You can
either use a cell in the worksheet as a parameter to the function or a
named range.

To get the uprotect to work you need to specify the activesheet

Activesheet.unprotect


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=158380

Microsoft Office Help



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
How to pass variables as arguments of a function Excel-craze Excel Worksheet Functions 1 August 12th 09 11:48 AM
Application.Run and pass variables to Sub Barb Reinhardt Excel Programming 2 September 26th 08 02:35 PM
Pass variables value to Shell wpw3 Excel Programming 0 March 7th 05 03:55 PM
Defining Variables that pass to other Subs JasonSelf[_14_] Excel Programming 2 August 11th 04 08:57 PM
can variables pass values Don[_11_] Excel Programming 3 November 1st 03 04:50 PM


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