+ Reply to Thread
Results 1 to 3 of 3

Only one cell can contain value

  1. #1
    Registered User
    Join Date
    01-13-2014
    Location
    Croatia
    MS-Off Ver
    Excel 2003
    Posts
    19

    Only one cell can contain value

    Hi,


    I have 4 cells and I want to restrict that only one of these cells can contain value using VBA.

    I have B1, B2, B3, B4 and if there is a text in B1 and I write something in B3 automatically delete B1 and leave text in B3 and so on...


    Thanks.

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Only one cell can contain value

    Insert the following Event Macro in the worksheet code area:
    Please Login or Register  to view this content.
    If you enter any value in the range B1 thru B4, the other cells in that range will be cleared.


    Because it is worksheet code, it is very easy to install and automatic to use:

    1. right-click the tab name near the bottom of the Excel window
    2. select View Code - this brings up a VBE window
    3. paste the stuff in and close the VBE window

    If you have any concerns, first try it on a trial worksheet.

    If you save the workbook, the macro will be saved with it.
    If you are using a version of Excel later then 2003, you must save
    the file as .xlsm rather than .xlsx

    To remove the macro:

    1. bring up the VBE windows as above
    2. clear the code out
    3. close the VBE window

    To learn more about macros in general, see:

    http://www.mvps.org/dmcritchie/excel/getstarted.htm

    and

    http://msdn.microsoft.com/en-us/libr...ffice.14).aspx

    To learn more about Event Macros (worksheet code), see:

    http://www.mvps.org/dmcritchie/excel/event.htm

    Macros must be enabled for this to work!
    Gary's Student

  3. #3
    Registered User
    Join Date
    01-13-2014
    Location
    Croatia
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Only one cell can contain value

    Nice, thank you!

+ 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. [SOLVED] When one cell equals value of another cell, then third cell displays text of fourth cell?
    By spookymyo in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-12-2021, 02:12 PM
  2. If Cell A is equal to Cell B replace the data from Cell A with Cell C. How can I do this.
    By tristanhathaway in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-01-2014, 08:05 PM
  3. [SOLVED] How to create/run "cell A equals Cell B put Cell C info in Cell D
    By abmb161 in forum Excel General
    Replies: 7
    Last Post: 02-05-2014, 02:20 AM
  4. Replies: 1
    Last Post: 11-06-2013, 02:56 AM
  5. Replies: 1
    Last Post: 11-03-2012, 09:05 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