Solved

MS Excel - Copy Link of Vertical to a Horizontal Target

Posted on 2013-01-23
4
411 Views
Last Modified: 2013-01-24
In Excel 2010, I'm trying to link source data which goes across a row to a target link column.   For example the source data runs across columns B410:CT410.  The linked cells could read cell A1 = B410, A2 = C410, A3 = D410.  There are so many rows I need to copy something down several hundred rows.  Is there a way to do this simply?  (Hint:  It's like Transpose but I'm looking to copy down links to render the same output.  This enables the target links to reflect source numbers if they change.)
0
Comment
Question by:CFMI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
redmondb earned 500 total points
ID: 38813017
Hi, CFMI.

If by "simply", you mean "without a macro", then I'm afraid I can't help. On the other hand, if a macro is OK, then please see the attached.

Click on the blue button to use the example you mentioned. Otherwise, change the addresses in Test_Transpose_Links(). It's happy with multiple rows...
xResponse = Transpose_Links("B410:CT412", "A1")

The code is...
Option Explicit

Sub Test_Transpose_Links()
Dim xResponse As String

xResponse = Transpose_Links("B410:CT410", "A1")

MsgBox xResponse

End Sub

Function Transpose_Links(xFrom_Str As String, xTo_Str As String) As String
Dim i     As Long
Dim j     As Long
Dim r     As Long
Dim c     As Long
Dim xSrce As Variant
Dim xDest As Variant
Dim xFrom As Range
Dim xTo   As Range
Dim xTest As Range
Dim xRow  As Long
Dim xCol  As Long

On Error Resume Next
    Set xFrom = Range(xFrom_Str)
    Set xTo = Range(xTo_Str)
    Set xTest = Intersect(xFrom, xTo.Resize(xFrom.Columns.Count, xFrom.Rows.Count))
On Error GoTo 0

If xFrom Is Nothing Then
    Transpose_Links = "Invalid ""From"" Range."
ElseIf xTo Is Nothing Then
    Transpose_Links = "Invalid ""To"" Range."
ElseIf xTo.Count > 1 Then
    Transpose_Links = """To"" Range must be one cell."
ElseIf Not xTest Is Nothing Then
    Transpose_Links = "Ranges overlap - " & xTest.Address & "."
End If

If Transpose_Links <> "" Then Exit Function

xSrce = xFrom
xDest = xSrce

xRow = xFrom.Cells(1, 1).Row - xTo.Row
xCol = xFrom.Cells(1, 1).Column - xTo.Column

For i = 1 To UBound(xSrce, 1)
    r = xRow + i
    c = xCol - i
    For j = 1 To UBound(xSrce, 2)
        r = r - 1
        c = c + 1
        xDest(i, j) = "=R[" & r & "]C[" & c & "]"
    Next
Next

xTo.Resize(UBound(xDest, 2), UBound(xDest, 1)).FormulaR1C1 = Application.Transpose(xDest)

Transpose_Links = WorksheetFunction.Substitute(Range("A3").Resize(UBound(xDest, 2), UBound(xDest, 1)).Address, "$", "") & " linked to " & xFrom_Str & " (" & xTo_Str & ")"

End Function

Open in new window

Regards,
Brian.Transpose-Links.xls
0
 
LVL 1

Author Closing Comment

by:CFMI
ID: 38814593
Thanks Brian.  I was looking for a function since it's easy for users.  Good to have the code though.
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38814759
Thanks, CFMI.

A few changes might help, if you're interested...
(1) Macro can be called by a shortcut key. (If they always use the same address range then that's all you'd need.)
(2) Prompt user for "From" range and "To" cell.

Anything else that they'd nedd?

Regards,
Brian.
0
 
LVL 1

Author Comment

by:CFMI
ID: 38815552
Nothing else needed.  Thank you!!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question