+ Reply to Thread
Results 1 to 4 of 4

keep value generated by formula

Hybrid View

  1. #1
    Registered User
    Join Date
    01-07-2008
    Posts
    65

    keep value generated by formula

    I have a worksheet with a series of random numbers, but I want them to keep their values once another value is entered into a neighboring cell (as opposed to changing to a new random number every time I change any cell in the worksheet). Does anyone know of a function that can do this?

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Quote Originally Posted by pilotwings64
    I have a worksheet with a series of random numbers, but I want them to keep their values once another value is entered into a neighboring cell (as opposed to changing to a new random number every time I change any cell in the worksheet). Does anyone know of a function that can do this?
    I don't know of a function, but you could achieve it with a VBA macro which fired on a Worksheet Selection Change event.

    The macro would use the new value as the ActiveCell and copy the adjacent random number and paste it back as a value.

    HTH

  3. #3
    Registered User
    Join Date
    01-07-2008
    Posts
    65
    I have not really gotten into VBA yet. What I need is something that interests me to be my first project. Can you give me the code for what you are talking about along with instructions about how to implement it?

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Quote Originally Posted by pilotwings64
    I have not really gotten into VBA yet. What I need is something that interests me to be my first project. Can you give me the code for what you are talking about along with instructions about how to implement it?
    OK, here's the code. It assumes your random numbers are in column A, and the adjacent entry you make is in column B. The code will obviously need modifying if these are different.

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Dim x As Integer
    
    If Intersect(Target, Range("A:A")) Is Nothing Then
        x = ActiveCell.Offset(0, -1)
        ActiveCell.Offset(0, -1) = x
    End If
    
    End Sub
    You need to go into the Visual Basic Environment (VBE), so press the ALT & F11 keys.

    Hopefully you should see a window on the left called the Project Window. In there you should see references to your sheet names and workbook name.

    Double click on the sheet where you have your random numbers, and you'll find another window opens on the right. At the top of this window are two drop down boxes. In the left hand one, select the 'Worksheet' object, and then in the drop down box on the right select the 'Change' event, and paste the code above between the
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    End Sub
    code

    Note the code above already has the Private....End Sub so don't duplicate it.

    Press ALT-F11 again to close the VBE

    Post back if you have any probs.

    Rgds

+ 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