Linking cells in excel file - excel

I want to link two cell in excel sheet. so i can edit cell values from both side.
for example:
I have two sheets in my excel.
sheet01 sheet02
A1 cell of sheet01 is connected with A1 cell of sheet02.
I can edit sheet01 cell and display value in sheet02
but sheet02 cell have =sheet01!A1
now i want a way to edit sheet02 A1 cell that's display data in A1 cell of sheet01.
simply, Both side communication for two linked cell in excel.

Use this code for the "Sheet1" object :
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
ThisWorkbook.Sheets("Sheet2").Range("A1").Value = Target.Value
End If
End Sub
You can also copy this code to the "Sheet2" object. You only have to change the Sheets("Sheet2") part into Sheets("Sheet1").

Related

How to display value based on highlighted cell?

Is there a way for a cell in Excel to show a value based on just selecting another cell? Example:
Column A has a list of car manufacturers. Column B has a list of vehicle models. When the user puts the cursor in cell A4 then cell D2 would display the content of cell B4. If the user clicks cell A3 then cell D2 now displays the content of cell B3. Is there a way to put a formula in cell D2 for this purpose without any macros? It would change value based on selecting a different cell in column A.
The code given below should work. It will be triggered everytime you select a value in Column "Make".
Paste the below code in the VB editor :
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim currentRow As Long
If Selection.Count = 1 Then
If Not Intersect(Target, Range("A:A")) Is Nothing Then
currentRow = Target.Row
Range("D2").Value = Cells(currentRow, 2).Value
End If
End If
End Sub
Go to Excel Developer Mode (Alt + F11)
Doube Click The Sheet1(Sheet1) in Left Side
Paste The code And Save
Sub test()
Worksheets("Sheet1").Activate
Set selectedCell = Application.ActiveCell
Range("D2").Value = selectedCell.Row
End Sub
D2 is a your highlighted Cell
And Goto Excel Sheet and Open Macro
Select Cell & use ctrl+q

Change hyperlink address automatically if the TextToDisplay changes

I need a solution for the hyperlink in Excel. I want to make my entire hyperlink address auto-update if I change the text of the hyperlink.
For example, TextToDisplay of the hyperlink is:
D:/attachment/1000.jpg
then I change the TextToDisplay of the hyperlink to:
D:/attachment/1001.jpg
The hyperlink address changes the same as the display text if I change the text of that hyperlink.
Formula Solution
The easist way would be to use a helper column. For example write your URLs in column A and use the following formula in column B to create the hyperlinks. Everytime you change the URL in column A it will change the hyperlink accordingly.
=HYPERLINK(A:A)
VBA Solution
Alternatively you can use the Worksheet_Change event in VBA.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cell As Range
For Each Cell In Target
If Cell.Hyperlinks.Count = 1 Then
Cell.Hyperlinks(1).Address = Cell.Value
End If
Next Cell
End Sub
Note that this code applies to all hyperlinks on the worksheet. If you want to limit it to a specific range do the following changes:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim AffectedRange As Range
Set AffectedRange = Intersect(Target, Me.Range("A:A"))
'limits the code to hyperlinks in column A.
'hyperlinks in other cells than column a are not changed
If Not AffectedRange Is Nothing Then
Dim Cell As Range
For Each Cell In AffectedRange
If Cell.Hyperlinks.Count = 1 Then
Cell.Hyperlinks(1).Address = Cell.Value
End If
Next Cell
End If
End Sub

Need to be able to double click cells on sheet1 to creat a list on sheet2

So I would like to be able to double click multiples cells on sheet1 to creat a list of sorts on sheet2.
The problem with the code I have now is that it just replaces content in one cell on sheet2 instead of seeing it already has content then transferring content to the next cell below it.
Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("E:P")) Is Nothing Then
If Target.Cells.Count = 1 then
Cancel = True
Sheets("Sheet1").Range("S13") = Target.Value
End If
End If
End Sub
So for example I need to be able to double click on E12 sheet1 it fills S13 on sheet2 with its content. Then I double click on E15 on sheet1 and it sees that S13 on sheet2 has content already so it fills S14 on sheet2 with its content.

Excel VBA Worksheet_Change refer to cells in another sheet with named range

I would like to use a user's input from a dropdown (yes/no) in sheet1 to hide/unhide rows in sheet2. A formula in sheet2 refers to the input in sheet1.
I also think that a named range (scope: workbook) on its own can only refer to the same sheet? Code below does not work but illustrates. Could not make other references work to named ranges with ThisWorkbook or similar.
Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("screener")) Is Nothing Then
With Sheets("Sheet2")
.Range("calc1.1").Rows.EntireRow.Hidden = (.Range("calc1.1").Cells(1, 1).Value = "No")
.Range("calc1.2").Rows.EntireRow.Hidden = (.Range("calc1.2").Cells(1, 1).Value = "No")
End With
End If
End Sub

Excel: Copy cell colour from a named range to a drop down menu

Can anyone help me? I have a named range in sheet1 and on sheet2 cells that reference the named range as a drop down list. I want to copy the cell colour from the named range sheet1 when it’s selected in the drop down list sheet2.
I’d be grateful for any support.
You can achieve this through VBA Worksheet_change event. Make sure that your colored range starts in cell A1 on sheet1. then in sheet2 enter this code in Worksheet module (not regular module).
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
x = Application.WorksheetFunction.Match(Range("A1").Value, Worksheets("Sheet1").Range("NamedRange"), 0)
Range("A1").Interior.Color = Worksheets("Sheet1").Range("A" & x).DisplayFormat.Interior.Color
End If
End Sub
This code assumes you have your data validation cell in in cell A1, but you can adjust Target.Adress and range("A1") part of code to your needs.

Resources