Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PJ PJ is offline
external usenet poster
 
Posts: 112
Default Ensure range of cells each contain an value

I have three cells (A3, B3 & C3) where I'm using data validation to control
the contents. My worksheet also has a macro button to generate a set of
reports when clicked. I want to update that macro by adding a check for
those three cells to ensure each has been completed, and cancel processing if
they have not.

Can someone provide guidance on setting up the IF statement?

If A3:C3 is blank (not sure how to code this part here)
MsgBox stating cell X or cells XXX are blank and required
Exit Sub
Else
' Do nothing, Ok to continue w/rest of macro
End If

Also, is it better to call a separate macro from my existing macro or just
add the check to the one I already have?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Ensure range of cells each contain an value

You can add the check in the same macro

Sub test()
If WorksheetFunction.CountA(Range("A3:C3")) < 3 Then
MsgBox "Not all cells have a value"
Else
MsgBox "Your code here"
End If
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"PJ" wrote in message ...
I have three cells (A3, B3 & C3) where I'm using data validation to control
the contents. My worksheet also has a macro button to generate a set of
reports when clicked. I want to update that macro by adding a check for
those three cells to ensure each has been completed, and cancel processing if
they have not.

Can someone provide guidance on setting up the IF statement?

If A3:C3 is blank (not sure how to code this part here)
MsgBox stating cell X or cells XXX are blank and required
Exit Sub
Else
' Do nothing, Ok to continue w/rest of macro
End If

Also, is it better to call a separate macro from my existing macro or just
add the check to the one I already have?

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
PJ PJ is offline
external usenet poster
 
Posts: 112
Default Ensure range of cells each contain an value

Thanks Ron, this does exactly what I need.

I'm curious though as to how difficult it would be to modify the response
msg to say cell B3 needs an entry, or B3 & C3 are empty. Also if the cells
are not continuous, can you use Range("A3,D5,J2,K7")? I have a few other
worksheets where I might like to add this type of validation check.

Thanks again.

"Ron de Bruin" wrote:

You can add the check in the same macro

Sub test()
If WorksheetFunction.CountA(Range("A3:C3")) < 3 Then
MsgBox "Not all cells have a value"
Else
MsgBox "Your code here"
End If
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"PJ" wrote in message ...
I have three cells (A3, B3 & C3) where I'm using data validation to control
the contents. My worksheet also has a macro button to generate a set of
reports when clicked. I want to update that macro by adding a check for
those three cells to ensure each has been completed, and cancel processing if
they have not.

Can someone provide guidance on setting up the IF statement?

If A3:C3 is blank (not sure how to code this part here)
MsgBox stating cell X or cells XXX are blank and required
Exit Sub
Else
' Do nothing, Ok to continue w/rest of macro
End If

Also, is it better to call a separate macro from my existing macro or just
add the check to the one I already have?

Thanks


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Ensure range of cells each contain an value

Try this

Sub test2()
Dim rng As Range
Dim cell As Range

Set rng = Range("A3,D5,J2,K7")

If WorksheetFunction.CountA(rng) < 4 Then
For Each cell In rng
If cell.Value = "" Then
MsgBox cell.Address(False, False) & " Is empty"
End If
Next cell
Else
MsgBox "Your code here"
End If

End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"PJ" wrote in message ...
Thanks Ron, this does exactly what I need.

I'm curious though as to how difficult it would be to modify the response
msg to say cell B3 needs an entry, or B3 & C3 are empty. Also if the cells
are not continuous, can you use Range("A3,D5,J2,K7")? I have a few other
worksheets where I might like to add this type of validation check.

Thanks again.

"Ron de Bruin" wrote:

You can add the check in the same macro

Sub test()
If WorksheetFunction.CountA(Range("A3:C3")) < 3 Then
MsgBox "Not all cells have a value"
Else
MsgBox "Your code here"
End If
End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"PJ" wrote in message ...
I have three cells (A3, B3 & C3) where I'm using data validation to control
the contents. My worksheet also has a macro button to generate a set of
reports when clicked. I want to update that macro by adding a check for
those three cells to ensure each has been completed, and cancel processing if
they have not.

Can someone provide guidance on setting up the IF statement?

If A3:C3 is blank (not sure how to code this part here)
MsgBox stating cell X or cells XXX are blank and required
Exit Sub
Else
' Do nothing, Ok to continue w/rest of macro
End If

Also, is it better to call a separate macro from my existing macro or just
add the check to the one I already have?

Thanks


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
Copy a worksheet and ensure range names stay local Darren Hill[_4_] Excel Programming 0 April 5th 07 08:21 AM
Ensure Named Range is in ThisWorkbook John Fuller Excel Programming 4 September 7th 06 06:19 PM
how do I ensure that the sum of two cells does not exceed a set fi lennysc14 Excel Worksheet Functions 3 July 5th 05 11:51 PM
Is it possible to ensure Calendar date is in range Robert Hargreaves Excel Programming 1 May 27th 05 08:38 PM
How to ensure function does not refer to cells outside of workbook? richardbok[_2_] Excel Programming 1 February 29th 04 08:56 PM


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