Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent leaving cell blank (empty) 1

Status
Not open for further replies.

bgreen

Programmer
Feb 20, 2003
185
0
0
CA
How can I prevent a user from leaving a cell blank (empty)?

I would like column A to not allow any blank cells. Preventing end user from entering data into a cell if there are any empty cells above it.
 
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   Dim curr_row As Long, curr_col As Long, prev_row As Long

   curr_row = Selection.Row
   curr_col = Selection.Column
   prev_row = curr_row - 1

   If prev_row > 0 And curr_col = 1 Then
      If Trim(Cells(prev_row, 1)) = "" Then
         MsgBox ("Please enter a value in the previous cell")
         Cells(prev_row, 1).Select
      End If
   End If
End Sub
 



Hi,
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Target
        If .Column <> 1 Then Exit Sub
        If .Row > 1 Then
            With .Offset(-1)
                If .Value = "" Then .Select
            End With
        End If
    End With
End Sub

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Where do I put this code? How do this work specifically for column A?

 



Right click the sheet tab, select, Vide Code and paste into the Code Window.

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 


oops

View Code

It already is set up to work on the FIRST column.

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top