+ Reply to Thread
Results 1 to 2 of 2

VBA code required to delete contents of a range and prevent further input.

  1. #1
    Forum Contributor
    Join Date
    03-09-2012
    Location
    Isle of Man
    MS-Off Ver
    Excel 2010
    Posts
    118

    VBA code required to delete contents of a range and prevent further input.

    I have a dropdown in cell D8 which when selected populates a number of cells but nothing in column F. The dropdown has five options.

    Could anyone provide me with VBA coding that deletes content in a range in column F and then prevents people from inputting to that range unless the correct option in the dropdown in cell D8 has been selected.

    Only one of the dropdown options should allow input to the range in column F. Any other option in cell D8 would delete the content in the range in column F and prevent further input to the range until the correct dropdown option has been selected.

    Thanks in anticipation.

    Declamatory
    Last edited by Declamatory; 11-07-2014 at 07:17 AM.

  2. #2
    Forum Contributor
    Join Date
    03-09-2012
    Location
    Isle of Man
    MS-Off Ver
    Excel 2010
    Posts
    118

    Re: VBA code required to delete contents of a range and prevent further input.

    Figured it out in the end. Phew!

    Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo ReEnableEvents
    Application.EnableEvents = False
    If Target.Address = Range("D8").Address Then
    Select Case UCase(Target.Value)
    Case ""
    Application.Undo
    GoTo ReEnableEvents
    Case UCase("Option 1")
    Range("F10:F48").ClearContents
    Case UCase("Option 2")
    Range("F10:F48").ClearContents
    Case UCase("Option 3")
    Range("F10:F48").ClearContents
    Case UCase("Option 4")
    Range("F10:F48").ClearContents
    End Select
    End If
    ReEnableEvents:
    Application.EnableEvents = True

    If Intersect(Target, Range("F10:F48")) Is Nothing Then Exit Sub
    On Error GoTo ExitPoint
    Application.EnableEvents = False
    If Range("D8").Value <> "Option 5" Then
    Application.Undo
    MsgBox "Cell D8 must be Option 5 in order to input to this cell", vbCritical, "Error"
    End If
    ExitPoint:
    Application.EnableEvents = True
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Java Code required to extract contents from a website
    By Siddharthsingh in forum Excel General
    Replies: 1
    Last Post: 10-07-2013, 01:23 PM
  2. Input Text Dependant On Cell Contents - Help Required.
    By heliskier89 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-15-2012, 08:22 AM
  3. VBA Code to delete the contents based on Color - Help needed
    By ragavendraph in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2012, 11:06 AM
  4. [SOLVED] Macro to delete and replace cell contents required
    By DancingElvisLives in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2011, 10:10 AM
  5. Delete cell contents in Code
    By garyi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2011, 12:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1