-2

I've searched the existing questions and found similar questions and answers but none that meet my requirements.

I have a spreadsheet where I wish to be able to click on links in one spreadsheet to take you to the second, placing the value in the cell clicked into a field in the second.

For example, the first sheet in column A will contain the units IT, Finance, and Networks

Click on any of these fields should take the user to the second sheet called "Sub Unit" placing the value of the cell in A1 where I can then write if statements to populate the sub unit list, for example clicking on IT would put IT in cell A1 and then via if statements in A3-A5 would make those as

Security, Support, Development

Then I would reuse similar VB code so that if someone clicks on a sub unit name, it takes them to a third sheet that will show the details for the sub unit.

Hope that makes sense,

I'm very new to VBA a so please indicate where I should place any code (e.g. in the tab, right click, view code, or in some different place)

2
  • 1
    I'm unable to reproduce to Copy cell value from sheet to another using the Hyperlink. But I can suggest you how to Copy cell value to another sheet using VBA(Macro) on Mouse click. Aug 11, 2018 at 11:04
  • That may work if you could post an example ill try it out Aug 12, 2018 at 12:34

1 Answer 1

0

At Sheet 1 press ALT+F11 to get the VB editor. Copy & Paste this code as standard module.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
MsgBox "Range " & Target.Address & " was double clicked"
 On Error Resume Next
    Dim xRg As Range
    Set xRg = Application.Selection
    Range("A80").Copy Sheet2.Range("A80")
    Application.Goto Worksheets("Sheet2").Range("A80"), True
End Sub

How it works:

  • Write some data in Cell A80 & double click the cell.
  • You get the Message box to confirm which cell has been clicked.
  • Press OK button.
  • Excel will Copy & Paste the content of A80 & place the cell pointer to Cell A80 of Sheet 2.

N.B.

  • Adjust the cell references & Sheet name in code as needed.
  • You may refer Range of cells to Copy & Paste.
  • To do so edit this line,,
  • Range("A80:A85").Copy Sheet2.Range("A80")
7
  • That works great but is there a way to stop the popup confirming the cell clicked and just have it go straight to the sheet2. Ignore this, worked it out :) Aug 20, 2018 at 10:01
  • Yes it's possible,, either put apostrophe' symbol at the beginning of this MsgBox "Range " & Target.Address & " was double clicked" or delete this line. Excel will read the next command line. Aug 20, 2018 at 10:42
  • Sorry, one more question. I've got it all working as above, but would like rather than copying a range, e.g. A80:A85 into A80, instead to copy the single cell double clicked into A80, but that cell to be any cell in a particular range. i.e. I put my values into A1 A2 A3 on sheet 1 for the person to double click on, and then only the value they double click is moved into A1 on sheet2 Aug 20, 2018 at 10:45
  • If you wanna to copy any specific one then need to be mentioned in the command line, Excel literally reads the command to act on ! Since you are looking for a Hyperlink type of effect that's Y the Mouse Click event has been used otherwise the selected Cell or Range can be copied also.!! ☺ Aug 20, 2018 at 10:47
  • Thanks, i went with this in the end 'Private Sub >Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) On Error Resume Next >Dim xRg As Range >Set xRg = Application.Selection > If Target.Address = "$A$80" Then >Range("A80").Copy Worksheets("Sheet2").Range("A1") >ElseIf Target.Address = "$A$79" Then Range("A79").Copy Worksheets("Sheet2").Range("A1") Else >Exit Sub >End If >Application.Goto Worksheets("Sheet2").Range("A1"), True >Range("B1").Value = Target >End Sub' Aug 21, 2018 at 11:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .