?
Solved

MS Excel - Copy Link of Vertical to a Horizontal Target

Posted on 2013-01-23
4
Medium Priority
?
420 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 1500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

770 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