• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Macros with Hyperlinks to data within a workbook

Need to create a macro that uses a hyperlink(s) in one worksheet that links to data in another works

  • This is the code format that you would use

    Votes: 0 0.0%
  • My suggesstion is . . . .

    Votes: 0 0.0%

  • Total voters
    0

BKGirl

New Member
Need to create a macro that uses a hyperlink(s) in one worksheet that links to data in another worksheet. Both sheets in the ‘Working spreadsheet 011314’ are constantly updated. Team members want to hyperlink data that is in column A (Project) of worksheet tab ‘2014 Projects’ to all related data that is in column E (Project) of worksheet tab ‘Detailed Project Master List’. Since a manager will be using this form, they would like for these linked cells of data to be formatted to another color once link is clicked.

a. As team members update and add new projects, they want column A to automatically link to all related data in column E by using a macro(see the whole row).
 

Attachments

  • Working spreadsheet 011314 for et.xlsx
    20.7 KB · Views: 15
Hi, BKGirl!

As a new user you might want (I'd say should and must) read this:
http://chandoo.org/forum/forums/new-users-please-start-here.14/

And regarding your issue, I don't fully understand what do you want to do, so please clarify these points:
a) You want to create an hyperlink from worksheet 'Detailed Project Master List' column E to worksheet '2014 Projects'... but to what column?, or just a link to the related row?
b) How do you come back from the linked destiny to the linker origin?, a command button, ...?
c) When you say that you want to format linked cells in other color after clicking on the link, you're referring to a permanent change of font color in column A (or that defined in a), if any)?

Regards!
 
See attached snapshot - hyperlinks are created for project names listed in '2014 Projects wks' (column A) to all related data in the 'Detailed Project Master List wks' (column E).

A command button will be fine if that will easier for the user. Again, users want a macro that will automatically create hyperlinks in 2014 Project to data in Detailed Project. This workbook is constantly being updated with new projects.

After the link is clicked in column A, the cells/rows retrieved for that project can turn light green (fill shading - cells for column E). This fill shading is not to be permanent (like a conditional format for the link).
 

Attachments

  • how to link worksheets using a macro.jpg
    how to link worksheets using a macro.jpg
    300.5 KB · Views: 15
Hi, BKGirl!

In your 1st post you wrote (bold is mine):
a. As team members update and add new projects, they want column A to automatically link to all related data in column E by using a macro(see the whole row).
A link can be to a cell, not to more than one cell.

In your last post you wrote:
1)
See attached snapshot - hyperlinks are created for project names listed in '2014 Projects wks' (column A) to all related data in the 'Detailed Project Master List wks' (column E).
Links work in a 1 to 1 relation, not in 1:N, so what do you want to do? Link to all projects of the clicked linker origin (which I don't see how to do it) or filter 2nd worksheet upon the value selected in 1st one (which it's possible)?

2)
A command button will be fine if that will easier for the user. Again, users want a macro that will automatically create hyperlinks in 2014 Project to data in Detailed Project. This workbook is constantly being updated with new projects.
Again, if the answer to the previous question is that of the last option, a command button is viable to return back.

3)
After the link is clicked in column A, the cells/rows retrieved for that project can turn light green (fill shading - cells for column E). This fill shading is not to be permanent (like a conditional format for the link).
If filtering is suitable, then we don't have to play with this.

Regards!
 
Yes, I would like to do your option of “or filter 2nd worksheet upon the value selected in 1st one (which it's possible)?" With the command button. Can you return to me how to do this. Appreciate all of your suggestions and help. :DD
 
Hi, BKGirl!

Give a look at this file:
https://dl.dropboxusercontent.com/u...11314 for et (for BKGirl at chandoo.org).xlsm

It uses 4 dynamic named ranges for easy and flexible reference as follows:

ProjectTable: 1st worksheet data range
=DESREF('2014 Projects'!$A$4;;;CONTARA('2014 Projects'!$A:$A)-2;CONTARA('2014 Projects'!$3:$3)) -----> in english: =OFFSET('2014 Projects'!$A$4,,,COUNTA('2014 Projects'!$A:$A)-2,COUNTA('2014 Projects'!$3:$3))

ProjectList: 1st column of previous
=DESREF(ProjectTable;;0;;1) -----> in english: =OFFSET(ProjectTable,,0,,1)

DetailTable: 2nd WS data range
=DESREF('Detailed Project Master List'!$A$2;;;CONTARA('Detailed Project Master List'!$A:$A)-1;CONTARA('Detailed Project Master List'!$1:$1)) -----> in english: =OFFSET('Detailed Project Master List'!$A$2,,,COUNTA('Detailed Project Master List'!$A:$A)-1,COUNTA('Detailed Project Master List'!$1:$1))

DetailList: 5th column of previous
=DESREF(DetailTable;;4;;1) -----> in english: =OFFSET(DetailTable,,4,,1)

In 1st worksheet you have 2 command buttons: Mode and Method.

Mode serves for switching between edit mode and link mode, otherwise if it's always linking whenever you click on column A it'd be a bit difficult to edit its values.

Method serves for switching between filter method and color method. Yes, you get a 2 by 1 (as I'd get the same bonus in my six-pack ;)).

When the workbook is opened the default values are edit and filter, but you can change them in the constants section of the below code.

In 2nd worksheet you have 1 command button to undo what done and return.

This is the code for workbook class module:
Code:
Option Explicit

Private Sub Workbook_Open()
  SetMode pgksModeEdit
  SetMethod pgksMethodFilter
End Sub
This is the code for 1st WS class module:
Code:
Option Explicit

Private Sub cmdMode_Click()
  ChangeMode
End Sub

Private Sub cmdMethod_Click()
  ChangeMethod
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  ' constants
  Const kiColumn = 1
  Const kiRow = 4
  ' declarations
  ' start
  '  edit, not col A, wrong row, empty cell, then quit
  If gsMode = pgksModeEdit Then Exit Sub
  If Application.Intersect(Target, Columns(kiColumn)) Is Nothing Then Exit Sub
  With Target
  If .Row < kiRow Or .Cells.Count > 1 Then Exit Sub
  If .Value = "" Then Exit Sub
  gsProject = .Value
  End With
  ' process
  FilterOrColor
  ' end
End Sub
This is the code for 2nd WS class module:
Code:
Option Explicit

Private Sub cmdBack_Click()
  UnFilterOrDisColor
End Sub
This is the code for the standard module (where all happens):
Code:
Option Explicit

' public constants
Public Const pgksModeEdit = "Edit"
Public Const pgksModeLink = "Link"
Public Const pgksMethodFilter = "Filter"
Public Const pgksMethodColor = "Color"

' public declarations
Public gsMode As String, gsMethod As String, gsProject As String

' global constants
'  ws & rng
Global Const gksWSProject = "2014 Projects"
Global Const gksRngProject = "ProjectList"
Global Const gksWSDetail = "Detailed Project Master List"
Global Const gksRngDetail = "DetailList"
'  mode & method
Global Const gksModeDefault = pgksModeEdit
Global Const gksMethodDefault = pgksMethodFilter

Sub SetMode(psMode As String)
  ' constants
  Const ksMode = "Mode "
  ' declarations
  Dim A As String
  ' start
  Select Case psMode
  Case pgksModeEdit, pgksModeLink
  A = psMode
  Case Else
  A = gksModeDefault
  MsgBox "Wrong mode parameter. Default used.", _
  vbApplicationModal + vbCritical + vbOKOnly, "Warning"
  End Select
  ' process
  gsMode = A
  Worksheets(gksWSProject).cmdMode.Caption = ksMode & gsMode
  ' end
End Sub

Sub SetMethod(psMethod As String)
  ' constants
  Const ksMethod = "Method "
  ' declarations
  Dim A As String
  ' start
  Select Case psMethod
  Case pgksMethodFilter, pgksMethodColor
  A = psMethod
  Case Else
  A = gksMethodDefault
  MsgBox "Wrong method parameter. Default used.", _
  vbApplicationModal + vbCritical + vbOKOnly, "Warning"
  End Select
  ' process
  gsMethod = A
  Worksheets(gksWSProject).cmdMethod.Caption = ksMethod & gsMethod
  ' end
End Sub

Sub ChangeMode()
  ' constants
  ' declarations
  ' start
  ' process
  Select Case gsMode
  Case pgksModeEdit
  SetMode pgksModeLink
  Case pgksModeLink
  SetMode pgksModeEdit
  Case Else
  SetMode gksModeDefault
  End Select
  ' end
End Sub

Sub ChangeMethod()
  ' constants
  ' declarations
  ' start
  ' process
  Select Case gsMethod
  Case pgksMethodFilter
  SetMethod pgksMethodColor
  Case pgksMethodColor
  SetMethod pgksMethodFilter
  Case Else
  SetMethod gksMethodDefault
  End Select
  ' end
End Sub

Sub FilterOrColor()
  ' constants
  Const klColor = &HFFFF00
  ' declarations
  Dim I As Long
  ' start
  If gsProject = "" Then MsgBox "wtf": Stop
  ' process
  With Worksheets(gksWSDetail)
  .Activate
  With .Range(gksRngDetail)
  Select Case gsMethod
  Case pgksMethodFilter
  .AutoFilter .Column, gsProject
  Case pgksMethodColor
  For I = 1 To .Cells.Count
  If .Cells(I, 1).Value = gsProject Then
  .Cells(I, 1).Interior.Color = klColor
  End If
  Next I
  End Select
  .Offset(-1, 0).Cells(1, 1).Select
  On Error Resume Next
  .Find(gsProject, , xlValues, xlWhole, , True).Select
  If Err.Number <> 0 Then
  Err.Clear
  MsgBox "No entries in master list for the selected project", _
  vbApplicationModal + vbCritical + vbOKOnly, "Warning"
  End If
  On Error GoTo 0
  End With
  End With
  ' end
End Sub

Sub UnFilterOrDisColor()
  ' constants
  ' declarations
  ' start
  ' process
  With Worksheets(gksWSDetail)
  .Activate
  With .Range(gksRngDetail)
  Select Case gsMethod
  Case pgksMethodFilter
  If .Parent.AutoFilter.FilterMode Then .Parent.ShowAllData
  Case pgksMethodColor
  .Cells.Interior.ColorIndex = xlNone
  End Select
  .Offset(-1, 0).Cells(1, 1).Select
  End With
  End With
  ' end
  Worksheets(gksWSProject).Activate
End Sub

Just advise if any issue.

Regards!
 
Thoroughly looking over this now in order to completely understand. Thank you very much for the help you have provided. If I have any issues, will give you a ping. :)
 
Hi, BKGirl!
Glad to help you. Waiting for your ping or your "yeah, I did it!".
Regards!

SirJB7 -

Again thank you for all of your help. Ran into a slight glitch (see attached spreadsheet). Need for data to come up in Column H (Project Name) of the Detailed Project Master List. For my actual spreadsheet I am not using column A and my data set begins at $B$62. When you click on 'Mode Link' button, information from column 'I' appears if it matches the project in '2014 Projects'.

And "Yeah, I am almost there!"
 

Attachments

  • for Chandoo - detailed pm list.xlsx
    20.7 KB · Views: 9
Hi, BKGirl!

Two things. First, I don't fully understand what you're asking for. Would you please elaborate and give a few examples? Second, if this is not related to the original question of the thread (the file has a worksheet with the same name but different structure) please start a new topic; if not, go on here.

Regards!
 
This thread is still related to the original thread. I just need assistance with the coding due to the Detailed Project Master List structure of the columns being a little different (attaching a sample worksheet with no code just to view to show what columns I need linked). The actual worksheet that I am working on for team members does not use any data in column A. My data set starts at column B62. In your coding for the original Detailed Project Master sheet for the Table range, you state to use: =OFFSET('Detailed Project Master List'!$A$2,,,COUNTA('Detailed Project Master List'!$A:$A)-1,COUNTA('Detailed Project Master List'!$1:$1)). Your DetailList range uses: =OFFSET(DetailTable,,4,,1)

The code that I am attempting to use according to the columns that the team wants, needs for column H (Project Name) to be linked. With the code that I am using, it points to column I (Menu Category). This is the code that I changed up due to not having data in column A: 'DetailTable'=OFFSET('[Master List - 1.22.14]Master List - 1.22'!$B$62,,,COUNTA('[Master List - 1.22.14]Master List - 1.22'!$B:$B)-1,COUNTA('Detailed Project Master List - 1.22.14'!$1:$1)) and 'DetailList' =OFFSET(DetailTable,,6,,1). Can you help with the correct coding for this?

Hope this is a little more clearer.
 

Attachments

  • Macros with Hyperlinks to data within a workbook et.xlsm
    48.9 KB · Views: 8
  • for Chandoo - detailed pm list.xlsx
    20.7 KB · Views: 2
  • for Chandoo - detailed pm list.xlsx
    20.7 KB · Views: 0
Ignore the duplicate attached 'for Chandoo - detailed pm list' worksheet. Again, this sheet is being sent to you as an example for what I need. Thank you.
 
Hi, BKGirl!
Gotcha, gonna give a look at it tomorrow.
Regards!

Thank you much - looking forward to receiving your assistance. :DD

Want you to know that everything else worked well from the coding that you sent on January 15th - just need to get the columns straight (start of data set) for the 'different' DetailTable that team members worked on -- as explained in previous email..
 
The code that I am attempting to use according to the columns that the team wants, needs for column H (Project Name) to be linked. With the code that I am using, it points to column I (Menu Category). This is the code that I changed up due to not having data in column A: 'DetailTable'=OFFSET('[Master List - 1.22.14]Master List - 1.22'!$B$62,,,COUNTA('[Master List - 1.22.14]Master List - 1.22'!$B:$B)-1,COUNTA('Detailed Project Master List - 1.22.14'!$1:$1)) and 'DetailList' =OFFSET(DetailTable,,6,,1). Can you help with the correct coding for this?
Hi, BKGirl!

You correctly changed the dynamic named ranges definition as:
a) starting cell: $B$62
b) column offset 6 instead of 4
... but they'll work fine only if:
1) you adjust the columns from:
COUNTA('Detailed Project Master List - 1.22.14'!$1:$1)
to:
COUNTA('Detailed Project Master List - 1.22.14'!$1:$1)-1
as column A it's left outside
2) columns Q:AF ("more stuff") have each one its title in row 1, neither empty nor merged cells, so as the previous count is correct
3) (I think that here we'll have problems) there's no data in column B in rows 2 thru 61, so as the following count is correct:
COUNTA('[Master List - 1.22.14]Master List - 1.22'!$B:$B)-1
If there're non empty cells you should tweak the final "-1" properly (e.g., if ranges B3:B11 and B34:B59 aren't empty, you should subtract -45: -9-34-1)

Give a look at your uploaded .xlsx file:
https://dl.dropboxusercontent.com/u...iled pm list (for BKGirl at chandoo.org).xlsx

I included the DetailTable definition, kept your DetailList definition with the offset of 6 and as you might see from the Name Manager (selection its name and clicking in the RefersTo text box) it's pointing to the right column: H, Project Name.

Please check the above assumptions, adjust your model properly and then test it again; if it still refuses to obey then upload a file with the same exact structure and data (either the actual or anonymized, but keeping all the cells usage.

Regards!
 
Thank you again for your help. Unfortunately it is not working. I put in the following for the DetailTable name range: =OFFSET('Master List - 1.22.14'!$B$62,,,COUNTA('Master List - 1.22.14'!$B:$B)-1,COUNTA('Master List - 1.22.14'!$1:$1))-1 for my actual team project and I get the following error message (see attached) - run-time error '1004': Application-defined or object-defined error.
 

Attachments

  • run time error for code.JPG
    run time error for code.JPG
    58.6 KB · Views: 3
Attached is a screenshot for you to see that Column A and previous rows have been grouped. Rows 1 through 60 are not all empty - just do not need this information listed in these rows. Need assistance asap - excuse the time pressure and thank you.
 

Attachments

  • sheet view (col A, B through H).JPG
    sheet view (col A, B through H).JPG
    39.5 KB · Views: 2
Please check the above assumptions, adjust your model properly and then test it again; if it still refuses to obey then upload a file with the same exact structure and data (either the actual or anonymized, but keeping all the cells usage.
Hi, BKGirl!
What about this? In my uploaded (based on your cropped file) file the ranges worked fine, but the worksheet structure wasn't the actual one, so... should we consult David Copperfield or Harry Potter? :p
Regards!
 
Hi, BKGirl!
What about this? In my uploaded (based on your cropped file) file the ranges worked fine, but the worksheet structure wasn't the actual one, so... should we consult David Copperfield or Harry Potter? :p
Regards!


Finally able to get back with you. Appreciate your patience. I am attaching a zip file that has workbooks in it - and the individual workbook that is structured to how team members want it (for the VBA macros that you have sent me).

The problem appears to be when you are in Mode Link/Method Filter approach, it will read from the respective project to column I (Category) in the Master List worksheet when it should link/read from column H (Project Name). The Mode Link/Method Color approach appears to be working well.


Team members are linking their new projects to tracking sheets where they will be information from - see items on sheets in purple text. Members know that what they type in column A of the initiative sheet must be an exact match in column 'B2' of their respective tracking sheets that will be saved on a server.

Consulting David Copperfield or Harry Potter may not be an option at this point (lol!). You have been doing a wonderful job so far!
:DD

Thank you and kind regards!
 

Attachments

  • for Chan site.zip
    283.4 KB · Views: 4
  • 2014 Timeline - to play with code.xlsm
    423.9 KB · Views: 4
Hi, BKGirl!
What about this? In my uploaded (based on your cropped file) file the ranges worked fine, but the worksheet structure wasn't the actual one, so... should we consult David Copperfield or Harry Potter? :p
Regards!

Hi - Sent you a zipped file and workbook that was basically actual structure/anonymized data on Tuesday. Did you receive? Let me know if you can assist me asap - meeting with team members later this afternoon :)eek:) and they would like to see the method filter selection to work (VERY IMPORTANT!) - reading from column H. Appreciate all of your help.
 
The problem appears to be when you are in Mode Link/Method Filter approach, it will read from the respective project to column I (Category) in the Master List worksheet when it should link/read from column H (Project Name). The Mode Link/Method Color approach appears to be working well.
 

Attachments

  • for Chan site.zip
    283.4 KB · Views: 2
Hi, BKGirl!
What about this? In my uploaded (based on your cropped file) file the ranges worked fine, but the worksheet structure wasn't the actual one, so... should we consult David Copperfield or Harry Potter? :p
Regards!


Change the column to 'H' instead of 'I' in the "Sub FilterOrColor" module (see code below). This appears to have helped some. Although there are times when you are in Mode Link/Method Color it will work fine, but if you switch it to Mode Link/Method Filter - data will attempt to read from Column I (and vice versa - switch from Filter to Color while in Link mode). If you could assist with this, would be greatly appreciated.

Code:
Sub FilterOrColor()
' constants
  Const klColor = &HFFFF00
  ' declarations
  Dim H As Long
  ' start
  If gsProject = "" Then MsgBox "wtf": Stop
  ' process
  With Worksheets(gksWSDetail)
  .Activate
  With .Range(gksRngDetail)
  Select Case gsMethod
  Case pgksMethodFilter
  .AutoFilter .Column, gsProject
  Case pgksMethodColor
  For H = 1 To .Cells.Count
  If .Cells(H, 1).Value = gsProject Then
  .Cells(H, 1).Interior.Color = klColor
  End If
  Next H
  End Select
  .Offset(-1, 0).Cells(1, 1).Select
  On Error Resume Next
  .Find(gsProject, , xlValues, xlWhole, , True).Select
  If Err.Number <> 0 Then
  Err.Clear
  MsgBox "No entries in Product Master list for the selected project", _
  vbApplicationModal + vbCritical + vbOKOnly, "Warning"
  End If
  On Error GoTo 0
  End With
  End With
  ' end
End Sub
 

Attachments

  • for Chan site.zip
    283.4 KB · Views: 4
Back
Top