Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro run if and cell in range is selected in VBA


Thanks Alex

I just tweaked what you wrote to:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim ShtRng(1 To 4) As Range
Dim Isect As Range
Dim i As Long

Set ShtRng(1) = Me.Range("B7:B106")
Set ShtRng(2) = Me.Range("C7:C106")
Set ShtRng(3) = Me.Range("D7:D106")
Set ShtRng(4) = Me.Range("E7:E106")

For i = 1 To 4
Set Isect = Intersect(Target, ShtRng(i))
If Not Isect Is Nothing Then
Call DoSomething(i)
Exit For
End If
Next i
Erase ShtRng


End Sub

Sub DoSomething(Idx As Long)
Select Case Idx
Case Is = 1
Application.StatusBar = "Please Enter The Workers Surname"
Case Is = 2
Application.StatusBar = "Please Enter The Workers Forename"
Case Is = 3
Application.StatusBar = "Does The Worker Have Their Own Transport?
*Presumed As No If Left Blank."
Case Is = 4
Application.StatusBar = "Enter Any Required Comments. *Any Entrie
Here Will Appear On Dispatch Sheet."
End Select
End Sub

This then worked an absolute treat.

Thanks Very Much For Your Help.

Celtic_Avenger
:) :) :) :) :

--
Celtic_Avenge
-----------------------------------------------------------------------
Celtic_Avenger's Profile: http://www.excelforum.com/member.php...fo&userid=1410
View this thread: http://www.excelforum.com/showthread.php?threadid=26125

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default Macro run if and cell in range is selected in VBA

Better still, in the SelectionChange Event Routine, add:

Dim StatusMsg(1 to 4) as string
StatusMsg(1)="Please Enter The Workers Surname"
(etc. for StatusMsg(2) to (4))

Then later ......

If Not Isect Is Nothing then Application.Statusbar = StatusMsg(i)
Exit For

(etc.)

AlexJ

"Celtic_Avenger" wrote in
message ...

Thanks Alex

I just tweaked what you wrote to:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim ShtRng(1 To 4) As Range
Dim Isect As Range
Dim i As Long

Set ShtRng(1) = Me.Range("B7:B106")
Set ShtRng(2) = Me.Range("C7:C106")
Set ShtRng(3) = Me.Range("D7:D106")
Set ShtRng(4) = Me.Range("E7:E106")

For i = 1 To 4
Set Isect = Intersect(Target, ShtRng(i))
If Not Isect Is Nothing Then
Call DoSomething(i)
Exit For
End If
Next i
Erase ShtRng


End Sub

Sub DoSomething(Idx As Long)
Select Case Idx
Case Is = 1
Application.StatusBar = "Please Enter The Workers Surname"
Case Is = 2
Application.StatusBar = "Please Enter The Workers Forename"
Case Is = 3
Application.StatusBar = "Does The Worker Have Their Own Transport?
*Presumed As No If Left Blank."
Case Is = 4
Application.StatusBar = "Enter Any Required Comments. *Any Entries
Here Will Appear On Dispatch Sheet."
End Select
End Sub

This then worked an absolute treat.

Thanks Very Much For Your Help.

Celtic_Avenger
:) :) :) :) :)


--
Celtic_Avenger
------------------------------------------------------------------------
Celtic_Avenger's Profile:

http://www.excelforum.com/member.php...o&userid=14101
View this thread: http://www.excelforum.com/showthread...hreadid=261256



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
Identifying a Selected Range in a Macro DCSwearingen Excel Discussion (Misc queries) 4 April 25th 06 04:01 PM
Macro run if and cell in range is selected in VBA Celtic_Avenger[_37_] Excel Programming 1 September 18th 04 03:28 PM
TO TOM OR KEN: macro to calculate selected range mary Excel Programming 3 January 19th 04 05:45 PM
Apply a macro to a pre-selected range of cells tim knowles Excel Programming 2 January 13th 04 01:12 PM
Execute a Macro when specific value is selected in a Range Kevin Excel Programming 3 November 21st 03 03:54 AM


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