Consulting

Results 1 to 3 of 3

Thread: Solved: Restrict mulilpe entries is N/A or No error is selcted

  1. #1

    Solved: Restrict mulilpe entries is N/A or No error is selcted

    [vba]
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("A3") <> "" Then
    Dim rngDV As Range
    Dim oldVal As String
    Dim newVal As String
    If Target.Count > 1 Then GoTo exitHandler
    On Error Resume Next
    Set rngDV = Intersect(Cells.SpecialCells(xlCellTypeAllValidation), Union(Columns(47), Columns(48), Columns(53), _
    Columns(54), Columns(59), Columns(60), Columns(65), Columns(66), Columns(70), Columns(71)))
    'rngDV.Select
    On Error GoTo exitHandler
    If rngDV Is Nothing Then GoTo exitHandler
    If Intersect(Target, rngDV) Is Nothing Then
    'do nothing
    Else
    Application.EnableEvents = False
    newVal = Target.Value
    Application.Undo
    oldVal = Target.Value
    Target.Value = newVal
    If oldVal = "" Then
    'do nothing
    Else
    If newVal = "" Then
    'do nothing
    Target.Value = "" 'optional line depending on what you want to happen if Delete is pressed
    'or an empty string is chosen
    Else
    Target.Value = oldVal & ", " & newVal
    Target.Columns.AutoFit
    End If
    End If
    End If
    exitHandler:
    Application.EnableEvents = True
    End If
    End Sub
    [/vba] This code needs tweaking, not written by me, it currently lets you put multiple entries in a cell.
    If however n/a or no_error is selected in the cell then disable multiple entreies for that cell only.
    Can anyone help

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If however n/a or no_error is selected in the cell
    What does this mean? Please take the time to explain your question clearly, if you want us to spend time answering. I'm disinclined to try to interpret this code to see what it is meant to be doing.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("A3") <> "" Then
    Dim rngDV As Range
    Dim oldVal As String
    Dim newVal As String
    If Target.Count > 1 Then GoTo exitHandler
    On Error Resume Next
    Set rngDV = Intersect(Cells.SpecialCells(xlCellTypeAllValidation), Union(Columns(12), Columns(47), Columns(48), _
    Columns(53), Columns(54), Columns(59), Columns(60), Columns(65), Columns(66), Columns(70), Columns(71)))
    'rngDV.Select
    On Error GoTo exitHandler
    If rngDV Is Nothing Then GoTo exitHandler
    If Intersect(Target, rngDV) Is Nothing Then
    'do nothing
    Else
    Application.EnableEvents = False
    newVal = Target.Value
    Application.Undo
    oldVal = Target.Value
    Target.Value = newVal
    If oldVal = "" Then
    'do nothing
    Else
    If newVal = "" Then

    'do nothing
    Target.Value = "" 'optional line depending on what you want to happen if Delete is pressed _
    'or an empty string is chosen
    ElseIf Target.Value = "N/A" Or Target.Value = "No_Error" Then

    Target.Value = newVal
    Else

    Target.Value = oldVal & ", " & newVal
    Target.Columns.AutoFit
    End If
    End If
    End If
    exitHandler:
    Application.EnableEvents = True
    End If
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •