Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default syntax needed to validate cells on spreadsheet

I am trying to write some code to test the following.
If column C contains a value then check that columns n to k also contain a
value. This check will apply to a number of rows on the activesheet. It is
possible that column c may not contain any values at all but I need a test to
ensure that if there are, then columns n to k are not empty. Would a Do
Until Not IsEmpty check on column c be more efficient in place of a For Each
type statement to avoid checking each row? However, I need to ensure that
the code does not get stuck in a continuous loop.
In summary the code needs to skip any empty cells in column c but if it
finds a value then check columns n to k are populated with a value. If these
columns contain a value on the same row as the test in column c then skip
else I need a message box warning the user that they've entered a value in
column c but not completed their input in columns n to k. Does that make
sense?
Can anyone kindly help please?
Many thanks
Jacqui
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default syntax needed to validate cells on spreadsheet

I think I'd use a formula in an adjacent cell (maybe insert a new column D and
have all things shift to the right):

=IF(C1="","",IF(COUNTA(L1:O1)=4,"","Please complete L:O!"))

Format that cell in big bold red letters.

========

In code:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range
Dim wks As Worksheet
Dim myRngToCheck As Range

Set wks = Worksheets("sheet1")

With wks
Set myRng = .Range("C1", .Cells(.Rows.Count, "C").End(xlUp))

For Each myCell In myRng.Cells
If myCell.Value = "" Then
'do nothing
Else
Set myRngToCheck = .Cells(myCell.Row, "K").Resize(1, 4)
If Application.CountA(myRngToCheck) _
< myRngToCheck.Cells.Count Then
MsgBox "Please fix Row: " & myCell.Row
End If
End If
Next myCell
End With
End Sub

Jacqui wrote:

I am trying to write some code to test the following.
If column C contains a value then check that columns n to k also contain a
value. This check will apply to a number of rows on the activesheet. It is
possible that column c may not contain any values at all but I need a test to
ensure that if there are, then columns n to k are not empty. Would a Do
Until Not IsEmpty check on column c be more efficient in place of a For Each
type statement to avoid checking each row? However, I need to ensure that
the code does not get stuck in a continuous loop.
In summary the code needs to skip any empty cells in column c but if it
finds a value then check columns n to k are populated with a value. If these
columns contain a value on the same row as the test in column c then skip
else I need a message box warning the user that they've entered a value in
column c but not completed their input in columns n to k. Does that make
sense?
Can anyone kindly help please?
Many thanks
Jacqui


--

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
VBA code to sum a row: syntax needed [email protected] Excel Discussion (Misc queries) 1 July 11th 05 06:41 PM
proper syntax in code needed Jim May Excel Programming 2 September 19th 04 12:44 AM
Please explain syntax needed Nobody[_3_] Excel Programming 1 June 3rd 04 10:50 PM
Multiple Condition syntax needed Jetheat Excel Programming 3 May 30th 04 11:18 PM
Syntax needed for With count Excel Programming 4 April 6th 04 02:33 PM


All times are GMT +1. The time now is 06:22 PM.

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"