getting value of named range

G

greg

I have a named range. Lets say it goes over lots of cells.
A1 to E20

Can I get the values out as a string? Single string.

I have tried some things like:

excel.Workbooks(MyWorkbook).Worksheets(MyWorksheet).Range(MyRange).value

any ideas
 
L

Lars-Åke Aspelin

I have a named range. Lets say it goes over lots of cells.
A1 to E20

Can I get the values out as a string? Single string.

I have tried some things like:

excel.Workbooks(MyWorkbook).Worksheets(MyWorksheet).Range(MyRange).value

any ideas


try this:

Function all_values_in_one_string(r As Range) As String
Dim s As String
For Each c In r
s = s & c.Value
Next c
all_values_in_one_string = s
End Function

Hope this helps / Lars-Åke
 
P

Per Jessen

I have a named range.  Lets say it goes over lots of cells.
A1 to E20

Can I get the values out as a string?  Single string.

I have tried some things like:

excel.Workbooks(MyWorkbook).Worksheets(MyWorksheet).Range(MyRange).value

any ideas

Hi

You need to loop through the cells. Look at this macro, it will loop
through the cells row by row.

Sub NamedRangeToString()
Dim nString As String
For Each c In Range("MyRange").Cells
nString = nString & c.Value
Next
MsgBox nString
End Sub

Regards,
Per
 
R

Ron Rosenfeld

I have a named range. Lets say it goes over lots of cells.
A1 to E20

Can I get the values out as a string? Single string.

I have tried some things like:

excel.Workbooks(MyWorkbook).Worksheets(MyWorksheet).Range(MyRange).value

any ideas

Not enough data to be sure what you really want, but brute force should work:

=====================
Sub foo()
Dim c As Range
Dim a As String

For Each c In Range("MyRange")
a = a & c.Value
Next c
Debug.Print a
End Sub
====================
--ron
 
B

Bob Phillips

Dim myArray

myArray = Application.Transpose(Range("myRange"))
MsgBox myArray(1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top