Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA not 100% need help with variable


I have this code that will only allow an "x" entered in a cell from
H9:J400.
The way it is now, If an input is entered in one of these cells other
than a "x" a message box pops up stating only an x can be entered here.
It will not currently allow me to delete and leave a cell blank(lets say
a mistake was made) and continue on with the sheet.

I need for this code to accept either an "x" or "" ANY SUGGESTIONS
PLEASE!

Here is the code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim TestCell As Range, Invalid As Boolean
If Not (Intersect(Target, Range("H9:J400")) Is Nothing) Then
For Each TestCell In Target.Cells
Invalid = Invalid Or TestCell.Value < "X"
Next TestCell
End If
If Invalid Then
MsgBox "You must enter 'X' here"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
End Sub


--
parteegolfer
------------------------------------------------------------------------
parteegolfer's Profile: http://www.excelforum.com/member.php...o&userid=31951
View this thread: http://www.excelforum.com/showthread...hreadid=521889

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default VBA not 100% need help with variable

Invalid = Invalid Or (TestCell.Value < "X" And TestCell.Value < "")

"parteegolfer" wrote:


I have this code that will only allow an "x" entered in a cell from
H9:J400.
The way it is now, If an input is entered in one of these cells other
than a "x" a message box pops up stating only an x can be entered here.
It will not currently allow me to delete and leave a cell blank(lets say
a mistake was made) and continue on with the sheet.

I need for this code to accept either an "x" or "" ANY SUGGESTIONS
PLEASE!

Here is the code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim TestCell As Range, Invalid As Boolean
If Not (Intersect(Target, Range("H9:J400")) Is Nothing) Then
For Each TestCell In Target.Cells
Invalid = Invalid Or TestCell.Value < "X"
Next TestCell
End If
If Invalid Then
MsgBox "You must enter 'X' here"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
End Sub


--
parteegolfer
------------------------------------------------------------------------
parteegolfer's Profile: http://www.excelforum.com/member.php...o&userid=31951
View this thread: http://www.excelforum.com/showthread...hreadid=521889


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VBA not 100% need help with variable

How about:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim TestCell As Range
Dim Invalid As Boolean
Dim myIntersect As Range

Set myIntersect = Intersect(Target, Me.Range("h9:j400"))

If myIntersect Is Nothing Then Exit Sub

On Error Resume Next
For Each TestCell In myIntersect.Cells
If LCase(TestCell.Text) = "x" _
Or LCase(TestCell.Text) = "" Then
'ok
Else
MsgBox "You must enter 'X' here"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Exit For 'stop looking for more errors
End If
Next TestCell
On Error GoTo 0

End Sub




parteegolfer wrote:

I have this code that will only allow an "x" entered in a cell from
H9:J400.
The way it is now, If an input is entered in one of these cells other
than a "x" a message box pops up stating only an x can be entered here.
It will not currently allow me to delete and leave a cell blank(lets say
a mistake was made) and continue on with the sheet.

I need for this code to accept either an "x" or "" ANY SUGGESTIONS
PLEASE!

Here is the code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim TestCell As Range, Invalid As Boolean
If Not (Intersect(Target, Range("H9:J400")) Is Nothing) Then
For Each TestCell In Target.Cells
Invalid = Invalid Or TestCell.Value < "X"
Next TestCell
End If
If Invalid Then
MsgBox "You must enter 'X' here"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
End Sub

--
parteegolfer
------------------------------------------------------------------------
parteegolfer's Profile: http://www.excelforum.com/member.php...o&userid=31951
View this thread: http://www.excelforum.com/showthread...hreadid=521889


--

Dave Peterson
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
Run-time Error'91: Object variable or With block variable not set DynamiteSkippy Excel Programming 4 September 26th 05 07:47 AM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


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