How to update two cells simultaneously, through one or the other?

Lurco

I have a Excel workbook calculator dependent on a few parameters. I want the client to be able to insert those parameters into an appropriate "client input" cell on every spreadsheet so he doesn't have to jump back and forth between spreadsheets.

Is there a good way to do it? I tried the following scheme, but it's buggy for reasons unknown to me:

  • make a VBA module declaring variables to hold my parameters
  • initialize them with appropriate initial values on the Workbook_Open event
  • make the specific sheets write those values into "client input" cells on Worksheet_Activate event
  • in a Worksheet_Deactivate event, if the "client input" cells are different among each other - update the VBA variables

This works sometimes, but not always. Is there a better way to do this?

EDIT:

This is my "GM" Module:

Option Explicit

Public perspective As String
Public RSS As String
Public Payback As Double

This is my "ThisWorkbook:

Private Sub Workbook_Open()
    GM.perspective = Worksheets("Hidden variables").Range("A1").Value
    GM.RSS = Worksheets("Hidden variables").Range("B2").Value
    GM.Payback = Worksheets("Hidden variables").Range("C3").Value
End Sub

Private Sub Workbook_Close()
    Worksheets("Hidden variables").Range("A1") = GM.perspective
    Worksheets("Hidden variables").Range("B2") = GM.RSS
    Worksheets("Hidden variables").Range("C3") = GM.Payback
End Sub

This is in my worksheet 1 (in worksheet 2 there is an analogous code):

Option Explicit

Private Sub Worksheet_Activate()
     'SIMULTANEOUS UPDATE p.1
     Worksheets("1").Range("I32") = GM.Payback
     Worksheets("1").Range("I29") = GM.RSS
     Worksheets("1").Range("I26") = GM.perspective
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
'BASIC PRICE CALCULATION
     If Target.Count > 1 Then Exit Sub
     If Target = Range("I32") _
     Or Target = Range("I29") _
     Or Target = Range("I26") _
     Or Target = Worksheets("Intro").Range("price") _
     Then

    Worksheets("Hidden variables").Range("condition") = 2
        Worksheets("Hidden variables").Range("basic_price") = Worksheets("Intro").Range("price").Value
        Range("M44").GoalSeek Goal:=0, ChangingCell:=Worksheets("Hidden variables").Range("basic_price")
        If Worksheets("Hidden variables").Range("basic_price").Value < 0 Then
            Range("M46") = "Error"
        Else
            Range("M46") = Worksheets("Hidden variables").Range("basic_price").Value
        End If
    Worksheets("Hidden variables").Range("condition") = 1
    End If
End Sub

Private Sub Worksheet_Deactivate()
'SIMULTANEOUS UPDATE p.2
        GM.Payback = Worksheets("1").Range("I32").Value
        GM.RSS = Worksheets("1").Range("I29").Value
        GM.perspective = Worksheets("1").Range("I26").Value
End Sub 
Maxime Porté

To avoid infinite loop, you can use a global variable Outside a function (at the begin of your module)

Public isUpdating As Double

inside your Worksheet_change

Private Sub Worksheet_Change(ByVal Target As Range)
    ' Check if an update is in progress. If so, exit the change
    if isUpdating then
        exit sub
    end if

    ' Begin of the update
    isUpdating = true

    ' Here your update

    ' End of the update
    isUpdating = false
End sub

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to update two cells simultaneously, through one or the other?

From Dev

How to iterate through a column in dataframe and update two new columns simultaneously?

From Dev

SQL: How to concatenate two cells from one column of multiple rows if all of the other row's cells are equal

From Dev

Two linked NSTables by NSArrayControllers are not updating simultaneously, if I update one of them

From Dev

How to Update Two table Data one after other In codeigniter?

From Dev

How to Update Two table Data one after other In codeigniter?

From Dev

How to iterate through two Arraylists simultaneously and making a "couple" of objects?

From Dev

Looping through two arrays simultaneously

From Dev

How to traverse two arrays simultaneously using only one for loop in rails

From Dev

Macro to select one cell if two other cells match

From Dev

How do I iterate through one array and move every other element to two new arrays in Swift?

From Dev

iterate through two std::lists simultaneously

From Dev

Not able to loop through two child nodes simultaneously

From Dev

How to loop through merged cells and read each one for text

From Dev

How to edit wpfdatagrid other cells while one of it's cell is invalid?

From Dev

How to zoom simultaneously on two ImageViews?

From Dev

How to print two list simultaneously?

From Dev

How to loop through cells

From Dev

Compare fields in two Object and update one to the other in Java

From Dev

Update one table based on data from two other tables

From Dev

Update one table based on data from two other tables

From Dev

update-alternatives has two entries, one in auto and other in manual

From Dev

Two OpenCV versions: update to one broke the other, though they should be separate

From Dev

How to update value in column cells based on other column cells in the same csv file bys using python?

From Dev

Can two users simultaneously share one pc

From Dev

Can one page be simultaneously in two working sets?

From Dev

R Shiny - filter two table and heatmap simultaneously (with cells of fix width)

From Dev

How to get range of cells in one cell separated by two blank spaces

From Dev

How do I match the text of two cells to one cell?

Related Related

  1. 1

    How to update two cells simultaneously, through one or the other?

  2. 2

    How to iterate through a column in dataframe and update two new columns simultaneously?

  3. 3

    SQL: How to concatenate two cells from one column of multiple rows if all of the other row's cells are equal

  4. 4

    Two linked NSTables by NSArrayControllers are not updating simultaneously, if I update one of them

  5. 5

    How to Update Two table Data one after other In codeigniter?

  6. 6

    How to Update Two table Data one after other In codeigniter?

  7. 7

    How to iterate through two Arraylists simultaneously and making a "couple" of objects?

  8. 8

    Looping through two arrays simultaneously

  9. 9

    How to traverse two arrays simultaneously using only one for loop in rails

  10. 10

    Macro to select one cell if two other cells match

  11. 11

    How do I iterate through one array and move every other element to two new arrays in Swift?

  12. 12

    iterate through two std::lists simultaneously

  13. 13

    Not able to loop through two child nodes simultaneously

  14. 14

    How to loop through merged cells and read each one for text

  15. 15

    How to edit wpfdatagrid other cells while one of it's cell is invalid?

  16. 16

    How to zoom simultaneously on two ImageViews?

  17. 17

    How to print two list simultaneously?

  18. 18

    How to loop through cells

  19. 19

    Compare fields in two Object and update one to the other in Java

  20. 20

    Update one table based on data from two other tables

  21. 21

    Update one table based on data from two other tables

  22. 22

    update-alternatives has two entries, one in auto and other in manual

  23. 23

    Two OpenCV versions: update to one broke the other, though they should be separate

  24. 24

    How to update value in column cells based on other column cells in the same csv file bys using python?

  25. 25

    Can two users simultaneously share one pc

  26. 26

    Can one page be simultaneously in two working sets?

  27. 27

    R Shiny - filter two table and heatmap simultaneously (with cells of fix width)

  28. 28

    How to get range of cells in one cell separated by two blank spaces

  29. 29

    How do I match the text of two cells to one cell?

HotTag

Archive