Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS Excel - Copy Link of Vertical to a Horizontal Target

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

916 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