Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 208
Default Preventing blank cells

I have a cell that has "P" in it by default. The only two values that should
go in this cell are "P" or "F". But at least one of those has to be in it.
How do I prevent the cell being left blank? And is there a way to ensure
that ONLY a "P" or an "F" is put in the cell?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,722
Default Preventing blank cells

Right click on sheet tab, view code, paste this in:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyCell As String
'Change callout here as desired
MyCell = "A2"

If Range(MyCell).Value = "P" Or Range(MyCell).Value = "F" Then
Exit Sub
Else
MsgBox "Please use a value of ""P"" or ""F"" in " & MyCell, , "Invalid Entry"
Application.EnableEvents = False
Range(MyCell).Select
End If
Application.EnableEvents = True
End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Bishop" wrote:

I have a cell that has "P" in it by default. The only two values that should
go in this cell are "P" or "F". But at least one of those has to be in it.
How do I prevent the cell being left blank? And is there a way to ensure
that ONLY a "P" or an "F" is put in the cell?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 208
Default Preventing blank cells

This is perfect. But what I really have is a 5X5 grid of cells that needs
this code. AND this same grid is repeated 64 times. So the first grid of
cells is:
H6:L6
H7:L7
H8:L8
H9:L9
H10:L10

the next grid is:

H14:L14
H15:L15
H16:L16
H17:L17
H18:L18

the next grid is:

H22:L22
H23:L23
H24:L24
H25:L25
H26:L26

this continues skipping 3 rows between each grid until the last grid which is:

H510:L510
H511:L511
H512:L512
H513:L513
H514:L514

How do I make this code apply to all the cells in all the grids?

"Luke M" wrote:

Right click on sheet tab, view code, paste this in:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyCell As String
'Change callout here as desired
MyCell = "A2"

If Range(MyCell).Value = "P" Or Range(MyCell).Value = "F" Then
Exit Sub
Else
MsgBox "Please use a value of ""P"" or ""F"" in " & MyCell, , "Invalid Entry"
Application.EnableEvents = False
Range(MyCell).Select
End If
Application.EnableEvents = True
End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Bishop" wrote:

I have a cell that has "P" in it by default. The only two values that should
go in this cell are "P" or "F". But at least one of those has to be in it.
How do I prevent the cell being left blank? And is there a way to ensure
that ONLY a "P" or an "F" is put in the cell?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,722
Default Preventing blank cells

Hmm. For that many cells, I'd use a different approach. For the P/F, use
Data-Validation, List, input
P,F
Note that you can other various options to help your user know what's going
on. However, we still have the issue of blank cells.

For this, I'd have a cell somewhere (say Z1) with a formula
=COUNTA(H6:L10,H14:L18,etc...)=1600
*1600 = 5*5*64

Then, modify the code I gave earlier. Downside is that macro no londer
automatically finds cell that is in error, but as it should be last cell user
modified, should be easy to find.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyCell As String
'Change callout here as desired
MyCell = "Z1"

If Range(MyCell).ValueThen
Exit Sub
Else
MsgBox "Please use a value of ""P"" or ""F"" in appropriate cells!", ,
"Invalid Entry"

End If
End Sub

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Bishop" wrote:

This is perfect. But what I really have is a 5X5 grid of cells that needs
this code. AND this same grid is repeated 64 times. So the first grid of
cells is:
H6:L6
H7:L7
H8:L8
H9:L9
H10:L10

the next grid is:

H14:L14
H15:L15
H16:L16
H17:L17
H18:L18

the next grid is:

H22:L22
H23:L23
H24:L24
H25:L25
H26:L26

this continues skipping 3 rows between each grid until the last grid which is:

H510:L510
H511:L511
H512:L512
H513:L513
H514:L514

How do I make this code apply to all the cells in all the grids?

"Luke M" wrote:

Right click on sheet tab, view code, paste this in:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyCell As String
'Change callout here as desired
MyCell = "A2"

If Range(MyCell).Value = "P" Or Range(MyCell).Value = "F" Then
Exit Sub
Else
MsgBox "Please use a value of ""P"" or ""F"" in " & MyCell, , "Invalid Entry"
Application.EnableEvents = False
Range(MyCell).Select
End If
Application.EnableEvents = True
End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Bishop" wrote:

I have a cell that has "P" in it by default. The only two values that should
go in this cell are "P" or "F". But at least one of those has to be in it.
How do I prevent the cell being left blank? And is there a way to ensure
that ONLY a "P" or an "F" is put in the cell?

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
Preventing user input for individual cells Michael.Tarnowski Excel Worksheet Functions 3 January 30th 09 12:05 AM
Maximum Number of Blank Cells between Non Blank Cells in a Range Mal Excel Worksheet Functions 5 November 3rd 07 08:21 AM
Problem with preventing objects moving and sizing with cells Nichelle H. New Users to Excel 2 May 31st 07 04:17 AM
Spacing in cells is preventing addition kris Excel Worksheet Functions 4 September 9th 06 06:40 PM
Preventing Duplicate Cells BenBlair Excel Discussion (Misc queries) 2 May 19th 05 06:08 PM


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