A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Programming
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Making a field compulsary before user leaves sheet



 
 
Thread Tools Display Modes
  #1  
Old May 26th 12, 09:33 PM
Rebecca Ellis Rebecca Ellis is offline
Junior Member
 
First recorded activity by ExcelBanter: May 2012
Posts: 2
Default Making a field compulsary before user leaves sheet

Hi, I am trying to make a field in a sheet mandatory so that when the user clicks a button I have added to take them to another sheet they are prompted that they must fill in a particular cell.

I have used the following code before to make a field compulsary before the user closes the whole file but I don't know how to adapt it to work when they leave the sheet:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim checkRng As Range
Set checkRng = Sheets("Sheet1").Range("A1")
If checkRng.Value = "" Then
Cancel = True
MsgBox "Please fill in " & _
checkRng.Address(False, False) & "."
End If
End Sub


Any help would be very much appreciated, thanks
Ads
  #2  
Old May 27th 12, 02:33 PM posted to microsoft.public.excel.programming
James Ravenswood
external usenet poster
 
Posts: 143
Default Making a field compulsary before user leaves sheet

On Saturday, May 26, 2012 4:33:06 PM UTC-4, Rebecca Ellis wrote:
> Hi, I am trying to make a field in a sheet mandatory so that when the
> user clicks a button I have added to take them to another sheet they are
> prompted that they must fill in a particular cell.
>
> I have used the following code before to make a field compulsary before
> the user closes the whole file but I don't know how to adapt it to work
> when they leave the sheet:
>
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> Dim checkRng As Range
> Set checkRng = Sheets("Sheet1").Range("A1")
> If checkRng.Value = "" Then
> Cancel = True
> MsgBox "Please fill in " & _
> checkRng.Address(False, False) & "."
> End If
> End Sub
>
>
> Any help would be very much appreciated, thanks
>
>
>
>
> --
> Rebecca Ellis


Put the following in the worksheet code area (NOT workbook code area) of the worksheet in question:

Private Sub Worksheet_Deactivate()
Dim checkRng As Range
Set checkRng = Sheets("Sheet1").Range("A1")
If checkRng.Value = "" Then
Sheets("Sheet1").Activate
MsgBox "Please fill in " & _
checkRng.Address(False, False) & "."
End If
End Sub
  #3  
Old May 27th 12, 02:39 PM posted to microsoft.public.excel.programming
James Ravenswood
external usenet poster
 
Posts: 143
Default Making a field compulsary before user leaves sheet

Put the following in the worksheet code area:

Private Sub Worksheet_Deactivate()
Dim checkRng As Range
Set checkRng = Sheets("Sheet1").Range("A1")
If checkRng.Value = "" Then
Sheets("Sheet1").Activate
MsgBox "Please fill in " & _
checkRng.Address(False, False) & "."
End If
End Sub

Hopefully this has not been truncated.
  #4  
Old May 27th 12, 04:02 PM
Rebecca Ellis Rebecca Ellis is offline
Junior Member
 
First recorded activity by ExcelBanter: May 2012
Posts: 2
Smile

Quote:
Originally Posted by James Ravenswood View Post
On Saturday, May 26, 2012 4:33:06 PM UTC-4, Rebecca Ellis wrote:
> Hi, I am trying to make a field in a sheet mandatory so that when the
> user clicks a button I have added to take them to another sheet they are
> prompted that they must fill in a particular cell.
>
> I have used the following code before to make a field compulsary before
> the user closes the whole file but I don't know how to adapt it to work
> when they leave the sheet:
>
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> Dim checkRng As Range
> Set checkRng = Sheets("Sheet1").Range("A1")
> If checkRng.Value = "" Then
> Cancel = True
> MsgBox "Please fill in " & _
> checkRng.Address(False, False) & "."
> End If
> End Sub
>
>
> Any help would be very much appreciated, thanks
>
>
>
>
> --
> Rebecca Ellis


Put the following in the worksheet code area (NOT workbook code area) of the worksheet in question:

Private Sub Worksheet_Deactivate()
Dim checkRng As Range
Set checkRng = Sheets("Sheet1").Range("A1")
If checkRng.Value = "" Then
Sheets("Sheet1").Activate
MsgBox "Please fill in " & _
checkRng.Address(False, False) & "."
End If
End Sub
It works!!!!!!!!!!
Thank you so much for taking the time to reply to my post, I have a deadline this evening for this work and can now send it working!!! Thank you so much again :-) :-)
 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Message if user leaves a field blank GillianX Excel Worksheet Functions 1 October 14th 08 05:40 PM
PivotTable with Server Page Field Leaves MS Query Application WindowOpen After Refresh. Dave[_63_] Excel Programming 0 December 3rd 07 12:38 AM
Cancel of text box leaves sheet unprotected Steve_n_KC Excel Worksheet Functions 2 May 24th 07 07:25 PM
I need to auto exit MS Excel when user leaves workbook open over . Jacques Excel Programming 2 February 18th 05 07:13 AM
Making cells compulsary to fill in on a worksheet abfabrob Excel Discussion (Misc queries) 7 February 4th 05 12:20 AM


All times are GMT +1. The time now is 03:14 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2004-2013 ExcelBanter.
The comments are property of their posters.