data validation VBA

ericlch16

Active Member
Joined
Nov 2, 2007
Messages
311
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
i have five columns A, B, C ,D ,E

the user needs to enter data in A before entering data in B or C or D or E

how to achieve this data validation in VBA? B,C,D,E I already force the user to enter today's date using data validation.

ActiveSheet.Range(Alpha_Column(m_StartDate) & irow & ":" & Alpha_Column(m_StartDate) & irow).Validation.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop, Operator:= xlGreaterEqual, Formula1:="=TODAY()"

can we have more data validation to B,C,D,E? so that before entering data they are forced to enter in A?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You could do this with a worksheet selection change event so that whenever a cell is chosen in columns B-E and the corresponding A column cell is empty, the user will be warned and the active cell will shift to A. Here's a macro to go into the worksheet module as follows:

  1. Right-Click the worksheet name tab and choose 'View Code'
  2. Copy the code below and paste it into the VB editor white space that appears.
  3. Close the VB editor and save the workbook. If you are using Excel 2007 or Excel 2010, be sure to save the workbook with a .xlsm file extension or the code will be lost when you close the workbook.
  4. When you open the workbook, you must enable macros for this to work.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Rw As Long
If Not Intersect(Target, Columns("B:E")) Is Nothing Then
    If Target.Count = 1 Then
        Rw = Target.Cells(1, 1).Row
        If IsEmpty(Cells(Rw, 1)) Then
            MsgBox "Fill Cell A" & Rw & " first!"
            Cells(Rw, 1).Select
        End If
    Else
        For Each c In Target
            If IsEmpty(Cells(c.Row, 1)) Then
                Rw = c.Row
                MsgBox "A column cells must be filled first!"
                Cells(Rw, 1).Select
                Exit Sub
            End If
        Next c
    End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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