Excel 2010 Hyperlinking Cells - excel

I have two sheets in an excel document (workbook). They have the same number of cells in the same arrangement. The first sheet contains summary information and the second sheet (in the corresponding cell) contains the more detailed information.
I want to hyperlink the sheets so that, a person can click the summary cell to be brought to the detailed cell.
I know I can use the following formula to create a hyperlinks:
HYPERLINK(link_location, [friendly_name])
And (at least in Excel 2010) the "link_location" entry must be in the format "#BOOK!Cell" where the quotes must be included.
However, when you click on a cell to make a selection, the formula processes it simply as BOOK!CELL. Its possible to drag and have the other cells auto populate with the BOOK!CELL format. But then I just have a bunch of broken cells. Any advice on how to automatically populate my first sheet with the correct format?

you need to use the subaddress to link to a place in the workbook. I would run this example below which would update all links to reflect the other sheet location. Change the name of the sheets to your two sheet names.
Sub FixMyLinks()
On Error Resume Next
Dim c As Range
Dim wsSummary As Worksheet
Dim wsDetails As Worksheet
Set wsSummary = ThisWorkbook.Sheets("Sheet1")
Set wsDetails = ThisWorkbook.Sheets("Sheet2")
For Each c In wsSummary.UsedRange.Cells
wsSummary.Hyperlinks.Add Anchor:=c, Address:="", SubAddress:=wsDetails.Name & "!" & Replace(c.Address, "$", ""), TextToDisplay:=c.Value
Next c
End Sub

Related

Copying Excel sheets with Hyperliknks. Without Sheets reference

I have hyperlinks in an big excel sheet that point to certain cells. (e.g. Link to cell A1, to AR50 etc..just to jump to different positions in the sheet)
When duplicate/copying these sheets, the reference (e. A1) is changed to "sheetname!A1".
So i have to change all references in the duplicated sheet.
has anyone an idea how to copy it just without the sheets reference??
Thank you
I don't think you can do this when you're inserting hyperlinks by using the "Insert Hyperlink dialog box". However, it can be accomplished by using the HYPERLINK formula. E.g. enter =HYPERLINK("#A100","Link") in the cell to establish a link. You'll see a clickable text "Link" (you can change this text to whatever you like, of course). Clicking the cell will route you to A100 in your current sheet. Once copied, the same cell in the copy will route you to A100 in this new sheet.
If you have used the Insert -> Link feature to create the links then you will need to use a VBA routine, such as the following
Sub updateLinks()
Const srcSheet As String = "SheetOne"
Const copySheet As String = "Sheet Two"
Dim link As Hyperlink
For Each link In Worksheets(copySheet).Hyperlinks
If InStr(1, link.SubAddress, srcSheet) Then
link.SubAddress = "'" & copySheet & "'!" & Split(link.SubAddress, "!")(1)
End If
Next link
End Sub
this example assumes that the tab copied had the name SheetOne, and that the copy was named Sheet Two
(if you don't know where to put this code then please see this article)

Matrix to create sheets and copy certain information

I have a unit matrix that illustrates work items for an apartment complex. It expands to 5 floors and has more work items than just the kitchen scope. My end goal is to have a sheet for each unit, listing the specific items needed for that unit. It would be very helpful once construction begins.
I want to do 2 things. 1 - Create new sheets for each unit (C5:C124) using the template. 2 - Copy over the information based on what is marked with an "X"
I know how to create a macros that will create blank sheets from the number of units I have. I'm stuck on integrating the template.
Thank you for reading.
Unit Scope Matrix
Template
Edit 1:
Here is my new code that can take a range of room#s and create new sheets from it. Now I would like to copy and paste the the row next the the according room# cell and paste in the appropriate sheet.
Sub CreateSheets()
Dim rng As Range
Dim cell As Range
On Error GoTo Errorhandling
'Creates popup box asking for the room numbers
Set rng = Application.InputBox(Prompt:="Select cell range:", _
Title:="Create sheets", _
Default:=Selection.Address, Type:=8)
For Each cell In rng
'Check if cell is not empty
If cell <> "" Then
'Insert worksheet and name the worksheet based on cell value
Sheets("Template").Copy After:=Sheets("Unit Types")
'Name new sheet based off two cells on Bid Summary List Cells (Bi and Di)
ActiveSheet.Name = "UNIT-" & cell
'This is where I think I should add the copy/paste lines... but I don't know how.
'Copy unit# row and paste in correct worksheet
'Range("XX:XX").Copy Range("XX:XX")
End If
'Continue with next cell in cell range
Next cell
'Go here if an error occurs
Errorhandling:
'Stop macro
End Sub
The code to copy the template and rename it is easy enough to make. Start recording, do one manually, stop recording, then press Alt-F11 to see how it's done, then steal from that to make your own function.
I suspect you'll end up with something that looks like
Function NewSheet(nm as String) as Worksheet
Dim template As Worksheet
set template = ActiveWorkbook.sheets('template')
set NewSheet = template.copy(ActiveWorkbook)
NewSheet.name = nm // change the tab name
NewSheet range('B1') = nm // add to the sheet as well
End Function
(warning: syntax and method names might unintentionally be wrong, this is intended to give you a head start, not do it for you)
and then you'll need to write a macro that loops through column C and calls your function. In this case you can ignore that NewSheet returns a new Worksheet object, but this way provides flexible code for future needs. Also, by isolating what you need to do to make a new worksheet as its own function that's called multiple times, It's easier to reason through and test, and the looping code that calls it is much easier to read as well.
Try searching for "Excel VBA looping examples" to get a head start on looping if you are unfamiliar.

Create a hyperlink to another sheet within the same workbook to first non-blank cell

I have a main sheet in which I manage my trades for currency on the FOREX. On that main sheet I have made buttons that I would like to hyperlink to the subsequent sheets that hold the daily data for each specific currency pair.
I am able to create a hyperlink to the sheet itself by using the hyperlink function but I want the hyperlink to actually find the first blank cell in column B and then count up 10 cells so that the last ten cells are visible on the sheet.
I have tried using Indirect, Offset, CountA, and Match combinations and variations to no avail. Please help.Main Screen Shot
Daily Sheet Screenshot
To simplify, you can replicate this code for each button. Change only one line for each button (and the subroutine name, of course)
Sub JPY_Daily_click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("JPY_Daily")
myrow = sh.Cells(sh.Rows.Count, 1).End(xlUp).Row - 10
sh.Activate
sh.Range("A" & myrow).Select
End Sub

VBA copy formula to other sheet, do not move "view"

I'm using a VBA routine to copy
Source sheet: named range (multiple 'selections')
Target sheet: copy-paste formula from cells in named range, to cells with a certain offset from a cell on the target sheet (this offset is depending on a certain selection).
I have two types of named ranges on the source sheet; one from which I only want to copy the values (=rng_operationeel_input_data), one from which I would like to copy to formulas (=rng_operationeel_formules). The formulas should be copied 'relatively', to have references on the target sheet (which are part of the copied values from the other range). For that reason, I can't use "targetCell.Formula = sourceCell.Formula", as it then literally copies the absolute formula. Not relative.
That's why I'm using sourceCell.
I do this in a for each loop over all cells in the source range, as the named range is not one single range (set of ranges).
Note. 'datasetReferenceCell' is the cell on the target sheet from which the offset is taken for pasting.
The problem is that, even if I use VBA to do the copy-pasting, without using 'select' somewhere, still at the end the user is confronted with the target sheet. (Excel will move to the target sheet)
This is only happening, for the copy-paste part.
How can I prevent this from happening?
edit: note that I am already using "Application.ScreenUpdating" (at start to false, at the end to true). I also have a MsgBox at the end of the routine (for info that routine was successful). Excel is moving to the target worksheet after the MsgBox is closed.
Below the VBA code part.
' dataset for weeknr found: save data to dataset
Dim dataRange As Range, dataField As Range
' for each cell in input data range: save value in dataset
Set dataRange = Range("rng_operationeel_input_data")
For Each dataField In dataRange
datasetReferenceCell.Offset(dataField.Row, dataField.Column).Value = dataField.Value
Next dataField
' !!! Following are only saved, not loaded, as it are formula based fields
' for each cell in formula range: paste formula
Set dataRange = Range("rng_operationeel_formules")
For Each dataField In dataRange
dataField.Copy
datasetReferenceCell.Offset(dataField.Row, dataField.Column).PasteSpecial (xlPasteFormulas)
'datasetReferenceCell.Offset(dataField.Row, dataField.Column).Formula = dataField.Formula 'not working, as relative formulas are required
Next dataField
The only way I was able to solve it was to reset the active sheet:
Public Sub routine()
Dim activeWs As Worksheet
Set activeWs = ThisWorkbook.ActiveSheet
.. code including copy & PasteSpecial ...
activeWs.Activate
End Sub

Unmerge cells and distribute contents in Excel (for mac) 2011

I have a spreadsheet with a large amount of data in. About half the cells are merged horizontally with other cells and contain names e.g. John Doe.
Does anyone know how to write a macro to unmerge the cells while distributing the value of the cell to all the cells that were previously merged?
Cheers
Jack
EDIT: The reason I am doing this is to check to see if two adjacent cells are equal i.e. is A1 = A2. But I run into problems when either cell is merged. If anyone knows a way around this problem without separating the cells and copying the data that would be even better!
The idea I provide below is tested for Excel 2010 VBA Win7. However, being not sure I hope it should work as for Mac, too (as this is rather set of standard properties and methods of Range object). If this doesn't work please let me know to delete my answer.
This simple code will work for selected area however it's quite easy to change it to any other range. Some other comment inside the code below.
Sub Unmerging_Selection()
Dim tmpAddress As String
Dim Cell As Range
'change Selection below for any other range to process
For Each Cell In Selection
'check if cell is merged
If Cell.MergeCells Then
'if so- check the range merged
tmpAddress = Cell.MergeArea.Address
'umnerge
Cell.UnMerge
'put the value of the cell to
Range(tmpAddress) = Cell
End If
Next
End sub
And the picture presenting before and after result:
I was able to get the solution from KazJaw to work on a mac with one edit, changing Cell.UnMerge to
ActiveSheet.UsedRange.MergeCells = False, as provided by Ron Debruin here: http://www.rondebruin.nl/mac/mac027.htm.
Sub Unmerging_Selection()
Dim tmpAddress As String
Dim Cell As Range
'change Selection below for any other range to process
For Each Cell In Selection
'check if cell is merged
If Cell.MergeCells Then
'if so- check the range merged
tmpAddress = Cell.MergeArea.Address
'umnerge
ActiveSheet.UsedRange.MergeCells = False
'put the value of the cell to
Range(tmpAddress) = Cell
End If
Next
End sub

Resources