A
A
Anatoly2021-11-13 19:49:35
excel
Anatoly, 2021-11-13 19:49:35

How to show certain data on click on a line?

I have Excel 2007, if the task is not solved on it, I can install another version.
An implementation on Google Sheets is also suitable.
There are 3 sheets: Managers, Clients and Orders.
How to make the data change at the top when clicking on a line with products.
The data is linked by client id and manager id.
On the last picture, the click was on the "Meat" cell, the data should be on top as shown in the picture.

Sheets Managers and Clients
618febac7b787081014184.png
618febb443e72394604581.png

618febbbda12b804701753.png

Updt. Through the "Source code" added a script of the form:
6190232cdfd5b708042614.png
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Intersect(Range("D5:E9"), Target) Is Nothing Then Exit Sub
    Range("B1").Value = "=ВПР(B" & ActiveCell.Row & ";клиенты!A:C;2;0)"
    Range("C1").Value = "=ВПР(B" & ActiveCell.Row & ";клиенты!A:C;3;0)"
    Range("B2").Value = "=ВПР(С" & ActiveCell.Row & ";менеджеры!A:C;2;0)"
    Range("C2").Value = "=ВПР(С" & ActiveCell.Row & ";менеджеры!A:C;3;0)"
End Sub

I get error 1004 on event.
Although the formula works fine without the macro:
=ВПР(B5;клиенты!A:C;2;0)
I can't figure out what's wrong?
The VLOOKUP function cannot work through a macro? What then to replace it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anatoly, 2021-11-14
@Tolly

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Intersect(Range("D5:E9"), Target) Is Nothing Then Exit Sub
    Range("B1").FormulaLocal = "=ВПР(B" & ActiveCell.Row & ";клиенты!A:C;2;0)"
    Range("C1").FormulaLocal = "=ВПР(B" & ActiveCell.Row & ";клиенты!A:C;3;0)"
    Range("B2").FormulaLocal = "=ВПР(C" & ActiveCell.Row & ";менеджеры!A:C;2;0)"
    Range("C2").FormulaLocal = "=ВПР(C" & ActiveCell.Row & ";менеджеры!A:C;3;0)"
End Sub

J
John Smith, 2021-11-13
@ClearAirTurbulence

You need to write macros in vba. By changing the cell on the SelectionChange event https
://stackoverflow.com/questions/23473721/execu...
each time the cursor is moved, it is checked against the condition\holes, and the necessary actions are performed.
But generally it is a perversion, for this purpose Access is.

G
Grigory Boev, 2021-11-13
@ProgrammerForever

For Google sheets there is onSelectionChange (event).

  1. Get cell address and content
    let value = range.getCell(1, 1).getValue()
  2. Search data for this query
    data.filter(row=>row[0]===value)
  3. And write the result in the desired cells
    range.setValues(outData)

Or you can select one cell for the current selection value, and look for values ​​using formulas with VLOOKUP / FILTER, such a hybrid method will work faster and is more resistant to editing the table structure.
If you need a ready-made solution - write to PM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question