Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Creating a Required Field

I am creating a Questionnaire with the following columns:

Column A €“ contains the list of questions.
Column B €“ contains Data Validation dropdown boxes with €œYes€ and €œNo€
choices.
Column C €“ used for inputting an Explanation.

For each question, the following business rule must be satisfied before
allowing the user to move to any other question:

If a user responds €œYes€ in column B, the active cell automatically becomes
the corresponding cell in column C, and the user MUST provide an explanation
(=20 characters in length) before being allowed to exit the cell.

Being a VBA novice, I do not have a clue how to program this. Any help
would be greatly appreciated.

Thanks,
Bob

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 457
Default Creating a Required Field

'This might work. Right click on your sheet tab, view code, paste all of
this in:
'=================
Dim xNeed As Boolean
Dim ExplainCell As Range


Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not (Intersect(Target, Range("B:B")) Is Nothing) Then
If Target.Count 1 Then Exit Sub
If UCase(Target.Value) = "YES" Then
xNeed = True
Set ExplainCell = Target.Offset(0, 1)
ExplainCell.Select

GoTo GetOut:
End If
ElseIf Not (Intersect(Target, Range("C:C")) Is Nothing) Then
If UCase(Target.Offset(0, -1).Value) = "YES" And _
Len(Target.Text) < 20 Then
MsgBox "Please provide a longer explanation"
Target.Select
GoTo GetOut:
End If
xNeed = False
End If
GetOut:
Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
If xNeed And _
Len(ExplainCell.Text) < 20 Then
ExplainCell.Select
MsgBox "Please provide an explanation"
End If
Application.EnableEvents = True
End Sub

'======================

--
Best Regards,

Luke M
"Bob" wrote in message
...
I am creating a Questionnaire with the following columns:

Column A - contains the list of questions.
Column B - contains Data Validation dropdown boxes with "Yes" and "No"
choices.
Column C - used for inputting an Explanation.

For each question, the following business rule must be satisfied before
allowing the user to move to any other question:

If a user responds "Yes" in column B, the active cell automatically
becomes
the corresponding cell in column C, and the user MUST provide an
explanation
(=20 characters in length) before being allowed to exit the cell.

Being a VBA novice, I do not have a clue how to program this. Any help
would be greatly appreciated.

Thanks,
Bob



  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Creating a Required Field

Hi Luke,
Thanks for your help. I really appreciate it.
Unfortunately, as soon as I moved my cursor to column B, I received the
following error message:

Run-time error 91
Object variable or With block variable not set.

I'm not sure how to fix this problem.
Also, for whatever its worth, row 1 contains my column headings. The
questions are contained in rows 2 - 10.

Regards,
Bob


"Luke M" wrote:

'This might work. Right click on your sheet tab, view code, paste all of
this in:
'=================
Dim xNeed As Boolean
Dim ExplainCell As Range


Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not (Intersect(Target, Range("B:B")) Is Nothing) Then
If Target.Count 1 Then Exit Sub
If UCase(Target.Value) = "YES" Then
xNeed = True
Set ExplainCell = Target.Offset(0, 1)
ExplainCell.Select

GoTo GetOut:
End If
ElseIf Not (Intersect(Target, Range("C:C")) Is Nothing) Then
If UCase(Target.Offset(0, -1).Value) = "YES" And _
Len(Target.Text) < 20 Then
MsgBox "Please provide a longer explanation"
Target.Select
GoTo GetOut:
End If
xNeed = False
End If
GetOut:
Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
If xNeed And _
Len(ExplainCell.Text) < 20 Then
ExplainCell.Select
MsgBox "Please provide an explanation"
End If
Application.EnableEvents = True
End Sub

'======================

--
Best Regards,

Luke M
"Bob" wrote in message
...
I am creating a Questionnaire with the following columns:

Column A - contains the list of questions.
Column B - contains Data Validation dropdown boxes with "Yes" and "No"
choices.
Column C - used for inputting an Explanation.

For each question, the following business rule must be satisfied before
allowing the user to move to any other question:

If a user responds "Yes" in column B, the active cell automatically
becomes
the corresponding cell in column C, and the user MUST provide an
explanation
(=20 characters in length) before being allowed to exit the cell.

Being a VBA novice, I do not have a clue how to program this. Any help
would be greatly appreciated.

Thanks,
Bob



.

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
Creating a Calculated Field in a Pivot Table for same field dza7 Excel Discussion (Misc queries) 3 October 21st 09 11:22 PM
Creating a Calculated Field in a Pivot Table for same field dza7 Excel Programming 3 October 21st 09 11:22 PM
Creating a Calculated Field From a Running Total Field Joe Excel Worksheet Functions 3 September 5th 08 02:09 AM
Linked excel field from access form field - help required. fishy Excel Programming 1 April 5th 08 02:43 PM
Field Required if another field is checked ** Kelly ******** Excel Programming 1 August 20th 03 10:44 PM


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