+ Reply to Thread
Results 1 to 6 of 6

Help with Code

  1. #1
    TimN
    Guest

    Help with Code

    FIRST.... Let me say thanks for all the help I have received. I am new to
    this position and new to VBA and nobody at the company knows it so You all
    have been a life saver for me!!!

    Here is the question:

    Can I write code so than in the worksheet If cell D1 has the value of "Y",
    and the user tries to enter data in E1, the cell (E1) would be disabled from
    any entries going in?

    Thanks again!!!

    TimN

  2. #2
    salut
    Guest

    RE: Help with Code

    In a protected sheet you can only change the unlocked cells.
    So try to protect this sheet first and then lock or unlock the cell "E1"
    depends on the value in cell "D1".

    Code would be

    if range("D1")="Y" then
    range("E1").locked=true
    else
    range("E1").locked=false
    endif

    "TimN" wrote:

    > FIRST.... Let me say thanks for all the help I have received. I am new to
    > this position and new to VBA and nobody at the company knows it so You all
    > have been a life saver for me!!!
    >
    > Here is the question:
    >
    > Can I write code so than in the worksheet If cell D1 has the value of "Y",
    > and the user tries to enter data in E1, the cell (E1) would be disabled from
    > any entries going in?
    >
    > Thanks again!!!
    >
    > TimN


  3. #3
    Dan Hatola
    Guest

    RE: Help with Code

    My only other thought is that since the default setting on cells is "locked",
    you might have to unlock all of the cells and then re-lock E1 if you want to
    be able to change other cells on the spreadsheet.

    Dan

    "salut" wrote:

    > In a protected sheet you can only change the unlocked cells.
    > So try to protect this sheet first and then lock or unlock the cell "E1"
    > depends on the value in cell "D1".
    >
    > Code would be
    >
    > if range("D1")="Y" then
    > range("E1").locked=true
    > else
    > range("E1").locked=false
    > endif
    >
    > "TimN" wrote:
    >
    > > FIRST.... Let me say thanks for all the help I have received. I am new to
    > > this position and new to VBA and nobody at the company knows it so You all
    > > have been a life saver for me!!!
    > >
    > > Here is the question:
    > >
    > > Can I write code so than in the worksheet If cell D1 has the value of "Y",
    > > and the user tries to enter data in E1, the cell (E1) would be disabled from
    > > any entries going in?
    > >
    > > Thanks again!!!
    > >
    > > TimN


  4. #4
    TimN
    Guest

    RE: Help with Code

    Great idea.

    Where do I put this code? Is it in the This Workbook module?
    All the rest of my code I have driving message boxes, user forms ets. I'm
    not sure how to work with this situation where the code just effects a cell
    in the workbook.

    "salut" wrote:

    > In a protected sheet you can only change the unlocked cells.
    > So try to protect this sheet first and then lock or unlock the cell "E1"
    > depends on the value in cell "D1".
    >
    > Code would be
    >
    > if range("D1")="Y" then
    > range("E1").locked=true
    > else
    > range("E1").locked=false
    > endif
    >
    > "TimN" wrote:
    >
    > > FIRST.... Let me say thanks for all the help I have received. I am new to
    > > this position and new to VBA and nobody at the company knows it so You all
    > > have been a life saver for me!!!
    > >
    > > Here is the question:
    > >
    > > Can I write code so than in the worksheet If cell D1 has the value of "Y",
    > > and the user tries to enter data in E1, the cell (E1) would be disabled from
    > > any entries going in?
    > >
    > > Thanks again!!!
    > >
    > > TimN


  5. #5
    Dan Hatola
    Guest

    RE: Help with Code

    If it is specific to one worksheet, you can put the code in that sheet module
    in the editor. You probably want to put it under a worksheet_change event

    Private Sub Worksheet_Change(ByVal Target As Range)

    Cells.Locked = False
    If Range("D1").Value = "Y" Then
    Range("E1").Locked = True
    End If
    End Sub




    "TimN" wrote:

    > Great idea.
    >
    > Where do I put this code? Is it in the This Workbook module?
    > All the rest of my code I have driving message boxes, user forms ets. I'm
    > not sure how to work with this situation where the code just effects a cell
    > in the workbook.
    >
    > "salut" wrote:
    >
    > > In a protected sheet you can only change the unlocked cells.
    > > So try to protect this sheet first and then lock or unlock the cell "E1"
    > > depends on the value in cell "D1".
    > >
    > > Code would be
    > >
    > > if range("D1")="Y" then
    > > range("E1").locked=true
    > > else
    > > range("E1").locked=false
    > > endif
    > >
    > > "TimN" wrote:
    > >
    > > > FIRST.... Let me say thanks for all the help I have received. I am new to
    > > > this position and new to VBA and nobody at the company knows it so You all
    > > > have been a life saver for me!!!
    > > >
    > > > Here is the question:
    > > >
    > > > Can I write code so than in the worksheet If cell D1 has the value of "Y",
    > > > and the user tries to enter data in E1, the cell (E1) would be disabled from
    > > > any entries going in?
    > > >
    > > > Thanks again!!!
    > > >
    > > > TimN


  6. #6
    Otto Moehrbach
    Guest

    Re: Help with Code

    A thought comes to mind. You say you want entry into that cell disabled.
    Do you want to just disable it and not tell the user anything about why he
    can't enter anything into that cell? Or do you want him to not be able to
    enter anything into that cell AND tell him so and why when he tries to do
    it? HTH Otto
    "TimN" <TimN@discussions.microsoft.com> wrote in message
    news:4E5E74B2-6A62-418B-8A73-E5D3A4704847@microsoft.com...
    > FIRST.... Let me say thanks for all the help I have received. I am new to
    > this position and new to VBA and nobody at the company knows it so You all
    > have been a life saver for me!!!
    >
    > Here is the question:
    >
    > Can I write code so than in the worksheet If cell D1 has the value of "Y",
    > and the user tries to enter data in E1, the cell (E1) would be disabled
    > from
    > any entries going in?
    >
    > Thanks again!!!
    >
    > TimN




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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