+ Reply to Thread
Results 1 to 2 of 2

One cell changes another or vice versa + change value of linked cell does not update

Hybrid View

  1. #1
    Registered User
    Join Date
    08-13-2009
    Location
    england
    MS-Off Ver
    Excel 2003
    Posts
    3

    One cell changes another or vice versa + change value of linked cell does not update

    I am doing a quick margin or selling price calculator based on enters costs.
    I have a code that allows updates/calculates of either the margin or selling price and vice versa ("B6" and "B7"). This works fine and please see code below.

    The problem is if I change one of the costs I want it to automatically update the selling price instead of manually pressing "F2" and "Enter" in the margin cell ("B6"). Any ideas of what I need to do to achieve this?

    MarginTest.xlsm - I have attached the sheet, any help would be appreciated.

    Capture.JPG

    Private Sub Worksheet_Change(ByVal Target As Range)
       If Target.Count > 1 Then Exit Sub
        If Target.Column < 2 Or Target.Column > 2 Then Exit Sub
        If Target.Row < 6 Or Target.Row > 7 Then Exit Sub
        Application.EnableEvents = False
        Select Case Target.Row
        Case Is = 6
            If Target.Offset(-2, 0) = "" Then
                Application.EnableEvents = True
                Exit Sub
            Else: Target.Offset(1, 0) = Target.Offset(-2, 0) / (1 - Target)
            End If
        Case Is = 7
            If Target.Offset(-3, 0) = "" Then
                Application.EnableEvents = True
                Exit Sub
            Else: Target.Offset(-1, 0) = (Target - Target.Offset(-3, 0)) / Target
            End If
        End Select
        Application.EnableEvents = True
        
    End Sub

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: One cell changes another or vice versa + change value of linked cell does not update

    Hi gemmott

    Try this
    Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Count > 1 Then Exit Sub
      If Not Target.Column = 2 Then Exit Sub
      Application.EnableEvents = False
      Select Case Target.Row
    
      Case Is = 1, 2, 3
        Range("B6").Activate
        Application.SendKeys Keys:="{F2}"
        Application.Wait (Now() + TimeValue("00:00:01"))
        Application.SendKeys "{ENTER}"
      Case Is = 6
        If Target.Offset(-2, 0) = "" Then
          Application.EnableEvents = True
          Exit Sub
        Else: Target.Offset(1, 0) = Target.Offset(-2, 0) / (1 - Target)
        End If
      Case Is = 7
        If Target.Offset(-3, 0) = "" Then
          Application.EnableEvents = True
          Exit Sub
        Else: Target.Offset(-1, 0) = (Target - Target.Offset(-3, 0)) / Target
        End If
      End Select
      Application.EnableEvents = True
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

+ 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. VBA code to change info in one cell so that other cell changes, and vice versa
    By tarab in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-21-2016, 12:57 PM
  2. How do I make one cell blank if another cell has data in it and vice-versa?
    By Nosilla in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-06-2014, 01:21 PM
  3. [SOLVED] Make value in cell A1 dependant on value in cell B1 and vice versa
    By tanktata in forum Excel General
    Replies: 9
    Last Post: 03-29-2012, 06:11 PM
  4. Enter and update ValuesIn Cell1 Based On Values In Cell 2 And Vice Versa.
    By miroper in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2010, 11:03 AM
  5. Page name from cell or vice versa
    By Audiguy82 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-19-2008, 06:21 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