Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Input validation using VBA

I am running two input validation rules, so I am running one using the input
validation feature in Excel, and one using VBA.

I have a couple of questions regarding the VBA run one. I am using the
following code and it is working fine, but I want to make a couple of changes.
Instead of have the limit as the number 7 I would like to use numbers from
the spreadsheet. The numbers are dynamic so can't be hard coded into the VBA
script, and the numbers are in the adjacent cells (B6:B15).
So for example I want C7 to be greater than B6.

Can any one offer any advice? My code is below.

Thank you.
R.



Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "C6:C15"

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target

If .Value < 7 Then

MsgBox "Invalid value, correct it"
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Input validation using VBA

Try this

from

If .Value < 7 Then

to

If .Value < .offset(0,1).value Then

this will compare the number against the cell immediately to the right in
colun C.



"VoxBox-Richard" wrote:

I am running two input validation rules, so I am running one using the input
validation feature in Excel, and one using VBA.

I have a couple of questions regarding the VBA run one. I am using the
following code and it is working fine, but I want to make a couple of changes.
Instead of have the limit as the number 7 I would like to use numbers from
the spreadsheet. The numbers are dynamic so can't be hard coded into the VBA
script, and the numbers are in the adjacent cells (B6:B15).
So for example I want C7 to be greater than B6.

Can any one offer any advice? My code is below.

Thank you.
R.



Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "C6:C15"

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target

If .Value < 7 Then

MsgBox "Invalid value, correct it"
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

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
What is input validation? Rich Excel Discussion (Misc queries) 1 September 7th 09 03:44 PM
Input Validation using VBA VoxBox-Richard Excel Programming 1 July 29th 08 01:13 PM
Data Input Validation Mark S[_2_] Excel Discussion (Misc queries) 5 February 24th 08 12:00 AM
Help with VBA Input Validation Jim[_56_] Excel Programming 1 January 24th 05 10:29 PM
validation of input in textbox Peer Excel Programming 3 July 23rd 04 03:06 PM


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

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

About Us

"It's about Microsoft Excel"