Solved

MS Excel - Copy Link of Vertical to a Horizontal Target

Posted on 2013-01-23
4
389 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now