#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default Macro Validation

I currently have a survey that is used by people nationally to rate a
department. They need to answer 9 questions then click "Submit" which has a
macro attached to save and hide their worksheet.

How can I add into the macro, code to stop the macro from running and
display an error box if someone tries to submit without having populated all
the fields (eg: cell L8)?

--
scheduler
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default Macro Validation

The existing code is pretty simple, it just copies the responses in cells
L*"L28 into a hidden sheet (for result compilation), hides the sheet that
person was using and saves and closes the workbook. It is:

Private Sub CommandButton1_Click()

ActiveSheet.Select
Range("L8:L28").Select
Selection.Copy

Sheets("Ratings Results").Visible = True
Sheets("Ratings Results").Select
Sheets("Ratings Results").Columns("F:F").Select
Selection.Insert Shift:=xlToRight
Sheets("Ratings Results").Range("A27:C27").Select
Sheets("Ratings Results").Visible = False

ActiveSheet.Select
Range("E4:J4").Select
ActiveWorkbook.Save
ActiveWindow.SelectedSheets.Visible = False

MsgBox "Thank you for completing the Customer Service Satisfaction
Survey", vbOKOnly

ActiveWorkbook.Save
ActiveWorkbook.Close

End Sub
--
scheduler


"Don Guillett" wrote:

As ALWAYS, post YOUR code for comments.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"scheduler" wrote in message
...
I currently have a survey that is used by people nationally to rate a
department. They need to answer 9 questions then click "Submit" which has
a
macro attached to save and hide their worksheet.

How can I add into the macro, code to stop the macro from running and
display an error box if someone tries to submit without having populated
all
the fields (eg: cell L8)?

--
scheduler



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default Macro Validation

This will check to make sure 21 cells are not blank or "space barred". Then,
it will do the original. It is NOT necessary to unhide the destination sheet
or select it.

Sub doitright()
'check range
If Evaluate("SumProduct(--(Len(trim(L8:L28)) 0))") < 21 Then
MsgBox "Please complete All items"
Exit Sub
End If
'do the copy insert
Range("L8:L28").Copy
Sheets("Ratings Results").Columns("F").Insert
Application.CutCopyMode = False
MsgBox "Thank you for completing the Customer" & _
"Service Satisfaction Survey", vbOKOnly

End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"scheduler" wrote in message
...
The existing code is pretty simple, it just copies the responses in cells
L*"L28 into a hidden sheet (for result compilation), hides the sheet that
person was using and saves and closes the workbook. It is:

Private Sub CommandButton1_Click()

ActiveSheet.Select
Range("L8:L28").Select
Selection.Copy

Sheets("Ratings Results").Visible = True
Sheets("Ratings Results").Select
Sheets("Ratings Results").Columns("F:F").Select
Selection.Insert Shift:=xlToRight
Sheets("Ratings Results").Range("A27:C27").Select
Sheets("Ratings Results").Visible = False

ActiveSheet.Select
Range("E4:J4").Select
ActiveWorkbook.Save
ActiveWindow.SelectedSheets.Visible = False

MsgBox "Thank you for completing the Customer Service Satisfaction
Survey", vbOKOnly

ActiveWorkbook.Save
ActiveWorkbook.Close

End Sub
--
scheduler


"Don Guillett" wrote:

As ALWAYS, post YOUR code for comments.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"scheduler" wrote in message
...
I currently have a survey that is used by people nationally to rate a
department. They need to answer 9 questions then click "Submit" which
has
a
macro attached to save and hide their worksheet.

How can I add into the macro, code to stop the macro from running and
display an error box if someone tries to submit without having
populated
all
the fields (eg: cell L8)?

--
scheduler




  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default Macro Validation

Thanks Don,

It worked a charm (and made the whole code a lot smaller).

Is there a way to get the macro to also check that if those cells (lets say
K8) is populated but with say a 1, 2 or 3 rating, that another cell (say M8)
must be also be populated (with a comment)?
--
scheduler


"Don Guillett" wrote:

This will check to make sure 21 cells are not blank or "space barred". Then,
it will do the original. It is NOT necessary to unhide the destination sheet
or select it.

Sub doitright()
'check range
If Evaluate("SumProduct(--(Len(trim(L8:L28)) 0))") < 21 Then
MsgBox "Please complete All items"
Exit Sub
End If
'do the copy insert
Range("L8:L28").Copy
Sheets("Ratings Results").Columns("F").Insert
Application.CutCopyMode = False
MsgBox "Thank you for completing the Customer" & _
"Service Satisfaction Survey", vbOKOnly

End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"scheduler" wrote in message
...
The existing code is pretty simple, it just copies the responses in cells
L*"L28 into a hidden sheet (for result compilation), hides the sheet that
person was using and saves and closes the workbook. It is:

Private Sub CommandButton1_Click()

ActiveSheet.Select
Range("L8:L28").Select
Selection.Copy

Sheets("Ratings Results").Visible = True
Sheets("Ratings Results").Select
Sheets("Ratings Results").Columns("F:F").Select
Selection.Insert Shift:=xlToRight
Sheets("Ratings Results").Range("A27:C27").Select
Sheets("Ratings Results").Visible = False

ActiveSheet.Select
Range("E4:J4").Select
ActiveWorkbook.Save
ActiveWindow.SelectedSheets.Visible = False

MsgBox "Thank you for completing the Customer Service Satisfaction
Survey", vbOKOnly

ActiveWorkbook.Save
ActiveWorkbook.Close

End Sub
--
scheduler


"Don Guillett" wrote:

As ALWAYS, post YOUR code for comments.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"scheduler" wrote in message
...
I currently have a survey that is used by people nationally to rate a
department. They need to answer 9 questions then click "Submit" which
has
a
macro attached to save and hide their worksheet.

How can I add into the macro, code to stop the macro from running and
display an error box if someone tries to submit without having
populated
all
the fields (eg: cell L8)?

--
scheduler






  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default Macro Validation

I can't tell wo seeing your file. If you like, send to my address below
along with these snippets on an inserted sheet along with clear explanations
and before/after examples.


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"scheduler" wrote in message
...
Thanks Don,

It worked a charm (and made the whole code a lot smaller).

Is there a way to get the macro to also check that if those cells (lets
say
K8) is populated but with say a 1, 2 or 3 rating, that another cell (say
M8)
must be also be populated (with a comment)?
--
scheduler


"Don Guillett" wrote:

This will check to make sure 21 cells are not blank or "space barred".
Then,
it will do the original. It is NOT necessary to unhide the destination
sheet
or select it.

Sub doitright()
'check range
If Evaluate("SumProduct(--(Len(trim(L8:L28)) 0))") < 21 Then
MsgBox "Please complete All items"
Exit Sub
End If
'do the copy insert
Range("L8:L28").Copy
Sheets("Ratings Results").Columns("F").Insert
Application.CutCopyMode = False
MsgBox "Thank you for completing the Customer" & _
"Service Satisfaction Survey", vbOKOnly

End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"scheduler" wrote in message
...
The existing code is pretty simple, it just copies the responses in
cells
L*"L28 into a hidden sheet (for result compilation), hides the sheet
that
person was using and saves and closes the workbook. It is:

Private Sub CommandButton1_Click()

ActiveSheet.Select
Range("L8:L28").Select
Selection.Copy

Sheets("Ratings Results").Visible = True
Sheets("Ratings Results").Select
Sheets("Ratings Results").Columns("F:F").Select
Selection.Insert Shift:=xlToRight
Sheets("Ratings Results").Range("A27:C27").Select
Sheets("Ratings Results").Visible = False

ActiveSheet.Select
Range("E4:J4").Select
ActiveWorkbook.Save
ActiveWindow.SelectedSheets.Visible = False

MsgBox "Thank you for completing the Customer Service Satisfaction
Survey", vbOKOnly

ActiveWorkbook.Save
ActiveWorkbook.Close

End Sub
--
scheduler


"Don Guillett" wrote:

As ALWAYS, post YOUR code for comments.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"scheduler" wrote in message
...
I currently have a survey that is used by people nationally to rate a
department. They need to answer 9 questions then click "Submit"
which
has
a
macro attached to save and hide their worksheet.

How can I add into the macro, code to stop the macro from running
and
display an error box if someone tries to submit without having
populated
all
the fields (eg: cell L8)?

--
scheduler





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
Validation Cell Macro MESTRELLA29 Excel Discussion (Misc queries) 4 September 19th 06 09:42 PM
E-mail macro - Field Validation tqdinh22 Excel Discussion (Misc queries) 3 August 21st 06 10:11 PM
How can I get a validation to run in a macro on a shared workbook? arewa Excel Discussion (Misc queries) 3 January 2nd 06 11:31 PM
Validation code for macro to run [email protected] Excel Discussion (Misc queries) 1 December 9th 05 02:28 PM
Validation!! Formula!! Macro?? Arvi Laanemets Excel Worksheet Functions 1 December 23rd 04 10:09 AM


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