View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Philip Philip is offline
external usenet poster
 
Posts: 156
Default Excel Cell Sequence

Hi,

1) Right-click on the sheet tab of the worksheet (by default it's something
like 'Sheet1') and click ''View Code
2) This opens the class module for the worksheet. This is where you can put
code that responds to events on the worksheet (like cell changes)
3) paste in this code (Worksheet_Change event handler):

CODE
Private Sub Worksheet_Change(ByVal Target As Range)

Dim iRow As Integer
Dim iCol As Integer
Dim iCheckCols As Integer
Dim sColumns As String
Dim bFailed As Boolean

iRow = Target.Row
iCol = Target.Column

If iCol = 1 Or iCol 4 Then Exit Sub
If VBA.IsEmpty(Target) Then Exit Sub
Application.EnableEvents = False

For iCheckCols = iCol To 1 Step -1
If VBA.IsEmpty(Cells(iRow, iCheckCols)) Then
sColumns = sColumns & iCheckCols & ","
bFailed = True
End If
Next

If VBA.Right(sColumns, 1) = "," Then sColumns = VBA.Left(sColumns,
VBA.Len(sColumns) - 1)

If bFailed = True Then
MsgBox "Please complete Column(s) " & sColumns & " first",
vbCritical + vbOKOnly
Target.Clear
Application.EnableEvents = True
End If
Application.EnableEvents = True

End Sub
<<<< END CODE

HTH

Philip
"Carol" wrote:

Hi,

I need to set up an excel spreadsheet with let's say 4 columns;
A1,B1,C1,D1.
The user cannot enter data into the any column unless all the previous
columns are completed.
They should be prevented from doing so and an error msg should appear
warning them.
Therefore it's a sequential flow - A first then B then C etc.

I hope someone can help me!!
Thanks in Advance
Carol