I have a spreadsheet with 5 columns containing 35 rows of data each. Can I select these and easily combine them to one column (for a single column with all 175 rows of data)?
Yes. What are the ranges and where are they to be combined ?
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
I have several spreadsheets where I want this done, and the number of columns and rows vary, but in this particular case its columns A to E, rows 11 to 45...
I'd like to combine them to column F..
Sounds like we might be opening a can of VBA worms but in terms of your specific example...
above would paste into F2 onwards (or from first non blank in F onwards)Public Sub Example() Dim vData As Variant vData = Range("A11:E45").Value For lngCol = 1 to UBound(vData,2) Step 1 Cells(Rows.Count,"F").End(xlUp).Offset(1).Resize(UBound(vData,1)).Value = Application.Index(vData,0,lngCol) Next lngCol End Sub
Hopefully that helps in part.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Thanks, that works well!Any way I can do this based on my selection, not on ranges set in the code?
It depends... given how varied the selection can be one approach would be something like:
but this is still open to error depending on size of range areas etc... output point being mid way up a blank column etc...Public Sub Example() Dim rngSource As Range, rngArea As Range, rngOutput As Range, vData As Variant, lngCol As Long On Error Resume Next Set rngSource = Selection Set rngOutput = Application.InputBox("Select Output Point", Type:=8) On Error GoTo 0 If rngOutput Is Nothing Or rngSource Is Nothing Then MsgBox "Invalid Input Range / Output Point - Routine Terminated", vbCritical, "Error" Else For Each rngArea In rngSource.Areas If rngArea.Cells.Count > 1 Then vData = rngArea.Value For lngCol = 1 To UBound(vData, 2) Step 1 Cells(Rows.Count, rngOutput.Column).End(xlUp).Offset(1).Resize(UBound(vData, 1)).Value = Application.Index(vData, 0, lngCol) Next lngCol Else Cells(Rows.Count, rngOutput.Column).End(xlUp).Offset(1).Value = rngArea.Value End If Next rngArea End If Set rngOutput = Nothing Set rngSource = Nothing End Sub
Last edited by DonkeyOte; 10-28-2009 at 01:03 PM.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Perfect, thank you very much!![]()
In Cell F1:
will stick all the data in the first row, columns A to E, into a single string (which can then be converted to another data type, if necessary).=CONCATENATE(A1:E1)
Have you actually tried your own suggestion ?
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
DonkeyOte: Is it possible to put the combined columns onto the clipboard rather than to a new column?
Why the clipboard ?
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
I'm using the spreadsheet to create variations on different words, I then need the results copied to another application. So I'm hoping I can select what I need and then click a button to put this onto the clipboard in a single list to be copied to the other application.
regards using the Clipboard with VBA
see: http://www.cpearson.com/excel/Clipboard.aspx
Given the thread is now running in two places (and you have responses on the other) I myself won't spend time large amounts of my time looking at this I'm afraid.
Also as detailed in the infraction you are obliged to provide links to your cross post(s).
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Chaitanya
Excel Expert and Excel Consultant
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks