Don't want cells left blank when using Data validation

trucker

New Member
Joined
Jan 19, 2003
Messages
37
I am using Data Validation and I don't want the user to go past a cell without putting in an entry. When I leave the box (ignore blank) unchecked it doesn't do anything after I have protected the document.

Help
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi Trucker,

Instead of using Data Validation let's try these Worksheet Event Procedures.

Right click the worksheet,choose View Code and paste the below code.

Note that I assume the cell is A1.

Code:
Public OLDVAL As Variant
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target = Range("A1") _
    And IsEmpty(Target) Then Target = OLDVAL
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    OLDVAL = Target.Value
End Sub
 
Upvote 0
I tried that and that didn't seem to work either. my cell is c4 I changed that but still when I pull up the template as a new document it will let me tab past the "Corporate Name" field without inputing anything...
 
Upvote 0
Did you originally apply this VBA to the template itself, or to the document that appears after choosing the template. If the latter (which it sounds like to me), then you didn't make the change to the template itself.
 
Upvote 0
Hi Trucker,

Right click the worksheet Tab,Choose View Code and Paste the Following Code:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address > [c4].Address Then
    If IsEmpty([c4]) Then
    MsgBox "Cell C4 Must Have A Value." _
    , vbCritical, "There Is A Problem!"
        [c4].Select
    End If
End If

End Sub


Hope this helps.
 
Upvote 0
Hi Trucker,

Right click the worksheet Tab,Choose View Code and Paste the Following Code:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address > [c4].Address Then
    If IsEmpty([c4]) Then
    MsgBox "Cell C4 Must Have A Value." _
    , vbCritical, "There Is A Problem!"
        [c4].Select
    End If
End If

End Sub


Hope this helps.
 
Upvote 0
Hi,

The below code works for all unlocked cells in a protected worksheet:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

For Each cl In Me.UsedRange.Cells
    If cl.Locked = False Then
        adr = cl.Address
        Exit For
    End If
Next

Application.ScreenUpdating = False
Application.EnableEvents = False

    If Not Target.Locked Then
        If IsEmpty(Target.Previous) Then
            If Target.Address <> adr Then
                Target.Previous.Select
            End If
        End If
    End If
Application.EnableEvents = True

End Sub

Hope this helps.
 
Upvote 0
What if I want to apply this to multiple cells, not all unlocked cells. Some cells are ok to leave blank.

Hi,

The below code works for all unlocked cells in a protected worksheet:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

For Each cl In Me.UsedRange.Cells
    If cl.Locked = False Then
        adr = cl.Address
        Exit For
    End If
Next

Application.ScreenUpdating = False
Application.EnableEvents = False

    If Not Target.Locked Then
        If IsEmpty(Target.Previous) Then
            If Target.Address <> adr Then
                Target.Previous.Select
            End If
        End If
    End If
Application.EnableEvents = True

End Sub
Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top