PC Review


Reply
Thread Tools Rate Thread

Cell specific code

 
 
Patrick C. Simonds
Guest
Posts: n/a
 
      25th Nov 2008
I want the code below to run only when cell B4 is selected and show the
Calendar only if the value in cell N2 is 0. If I click on cell B4 and cell
N2 is greater than 0, my message displays just as I want it to. But for some
reason Calendar displays no matter what cell I select. Where have I gone
wrong?


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Application.Intersect(Target, Range("B4")) Is Nothing Then

If Range("N2").Value > 0 Then GoTo NotBlank
End If

Calendar.Show

GoTo Finished

NotBlank:
MsgBox "This Workbook contains Vacation data. That data must be removed
before you can change the year. If you want to start a new year, please use
the Template."

Finished:

End Sub

 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      25th Nov 2008
Hi

If Not Application.Intersect(Target, Range("B4")) Is Nothing Then
If Range("N2").Value > 0 Then GoTo NotBlank
Calendar.Show
End If

Regards,
Per

"Patrick C. Simonds" <(E-Mail Removed)> skrev i meddelelsen
news:(E-Mail Removed)...
>I want the code below to run only when cell B4 is selected and show the
>Calendar only if the value in cell N2 is 0. If I click on cell B4 and cell
>N2 is greater than 0, my message displays just as I want it to. But for
>some reason Calendar displays no matter what cell I select. Where have I
>gone wrong?
>
>
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
>
> If Not Application.Intersect(Target, Range("B4")) Is Nothing Then
>
> If Range("N2").Value > 0 Then GoTo NotBlank
> End If
>
> Calendar.Show
>
> GoTo Finished
>
> NotBlank:
> MsgBox "This Workbook contains Vacation data. That data must be removed
> before you can change the year. If you want to start a new year, please
> use the Template."
>
> Finished:
>
> End Sub
>


 
Reply With Quote
 
Patrick C. Simonds
Guest
Posts: n/a
 
      26th Nov 2008
Problem is, now my MsgBox located at NotBlank: is displayed every time a
cell is clicked on, so this event does not seem to be restricted to clicking
on cell B4 only.

Is there any way to restrict this code to running only when cell B4 is
clicked on?


"Per Jessen" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi
>
> If Not Application.Intersect(Target, Range("B4")) Is Nothing Then
> If Range("N2").Value > 0 Then GoTo NotBlank
> Calendar.Show
> End If
>
> Regards,
> Per
>
> "Patrick C. Simonds" <(E-Mail Removed)> skrev i meddelelsen
> news:(E-Mail Removed)...
>>I want the code below to run only when cell B4 is selected and show the
>>Calendar only if the value in cell N2 is 0. If I click on cell B4 and cell
>>N2 is greater than 0, my message displays just as I want it to. But for
>>some reason Calendar displays no matter what cell I select. Where have I
>>gone wrong?
>>
>>
>> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
>>
>> If Not Application.Intersect(Target, Range("B4")) Is Nothing Then
>>
>> If Range("N2").Value > 0 Then GoTo NotBlank
>> End If
>>
>> Calendar.Show
>>
>> GoTo Finished
>>
>> NotBlank:
>> MsgBox "This Workbook contains Vacation data. That data must be
>> removed before you can change the year. If you want to start a new year,
>> please use the Template."
>>
>> Finished:
>>
>> End Sub
>>

>


 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      26th Nov 2008
This should do it:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(Target, Range("B4")) Is Nothing Then
If Range("N2").Value > 0 Then
MsgBox "This Workbook contains Vacation data." & vbLf & _
"That data must be removed before you can change the year." _
& vbLf & "If you want to start a new year, please use the
Template."
Else
Calendar.Show
End If
End If
End Sub

Regards,
Per

"Patrick C. Simonds" <(E-Mail Removed)> skrev i meddelelsen
news:usPdT2$(E-Mail Removed)...
> Problem is, now my MsgBox located at NotBlank: is displayed every time a
> cell is clicked on, so this event does not seem to be restricted to
> clicking on cell B4 only.
>
> Is there any way to restrict this code to running only when cell B4 is
> clicked on?
>
>
> "Per Jessen" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Hi
>>
>> If Not Application.Intersect(Target, Range("B4")) Is Nothing Then
>> If Range("N2").Value > 0 Then GoTo NotBlank
>> Calendar.Show
>> End If
>>
>> Regards,
>> Per
>>
>> "Patrick C. Simonds" <(E-Mail Removed)> skrev i meddelelsen
>> news:(E-Mail Removed)...
>>>I want the code below to run only when cell B4 is selected and show the
>>>Calendar only if the value in cell N2 is 0. If I click on cell B4 and
>>>cell N2 is greater than 0, my message displays just as I want it to. But
>>>for some reason Calendar displays no matter what cell I select. Where
>>>have I gone wrong?
>>>
>>>
>>> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
>>>
>>> If Not Application.Intersect(Target, Range("B4")) Is Nothing Then
>>>
>>> If Range("N2").Value > 0 Then GoTo NotBlank
>>> End If
>>>
>>> Calendar.Show
>>>
>>> GoTo Finished
>>>
>>> NotBlank:
>>> MsgBox "This Workbook contains Vacation data. That data must be
>>> removed before you can change the year. If you want to start a new year,
>>> please use the Template."
>>>
>>> Finished:
>>>
>>> End Sub
>>>

>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to edit the code to fit image within specific cell? Eric Microsoft Excel Programming 5 10th Feb 2010 06:12 AM
Code to copy the formulae of one cell to all the cell in the rangewith the specific cell and columnnumber changing Options Yuvraj Microsoft Excel Misc 0 29th Jun 2009 11:20 AM
Code to copy the formulae of one cell to all the cell in the rangewith the specific cell and columnnumber changing Yuvraj Microsoft Excel Misc 0 26th Jun 2009 06:01 PM
Use a code to populate a cell with a specific value =?Utf-8?B?YnJhdmVU?= Microsoft Excel Worksheet Functions 5 13th Apr 2007 10:02 PM
UDF code to find specific text in cell comments, then average cell values bruch04 Microsoft Excel Programming 3 5th Dec 2005 10:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:57 AM.