Solved

MS Excel - Copy Link of Vertical to a Horizontal Target

Posted on 2013-01-23
4
380 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Nothing else needed.  Thank you!!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
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 demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

744 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

15 Experts available now in Live!

Get 1:1 Help Now