Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 15th, 2007, 01:17 PM
Registered User
 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Concatenate cells into a variable

I'm trying to concatenate a few cells:

Function ConcRange(Substrings As Range)

    Dim CLL As Variant
    
    For Each CLL In Substrings.Cells
        ConcRange = ConcRange & CLL.Value
    Next CLL
    
    ConcRange = Mid$(ConcRange, 1)
    
End Function

I'm calling the function with
    rw = rw - 1
    rStr = ConcRange(Range(Cells(rw, 1), Cells(rw, 15)))

When I run this code, it's always empty even though the Workbook was opened successfully and the range contains data. Am I missing something else?

Thanks
nori233
 
Old January 21st, 2007, 06:12 PM
Registered User
 
Join Date: Jan 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nori,
One possibility is that the data is not on the active sheet in which case you would need to qualify both the range and the cells objects with the sheet reference and possibly also the work book. The code below seems to work fine for data held in the range A1 to O2 in sheet1 of book1 and it works from any additional workbook I have open.
Apart from that, I can't think what's wrong
My code is below

Public Function ConcRange(substrings As Range)
Dim CLL As Variant
For Each CLL In substrings.Cells
ConcRange = ConcRange & CLL.Value
Next CLL
ConcRange = Mid$(ConcRange, 1)
End Function


Sub UseConcRange()
Dim rw As Long
Dim rStr As String
For rw = 1 To 2
With Workbooks("book1").Sheets("sheet1")
rStr = ConcRange(.Range(.Cells(rw, 1), .Cells(rw, 15)))
End With
MsgBox rStr
Next rw
End Sub






Similar Threads
Thread Thread Starter Forum Replies Last Post
concatenate records davehodges Access 5 November 1st, 2007 10:13 AM
Hyperlink (Concatenate) JEHalm Excel VBA 1 January 11th, 2006 01:09 PM
string concatenate phelkuizon Classic ASP Databases 1 September 13th, 2004 04:08 AM
concatenate with characters lily611 ADO.NET 1 July 21st, 2004 08:10 AM
How to Concatenate Data mbbolz SQL Language 4 April 1st, 2004 04:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.