Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Text into one cell

Hi!

I have text spread in several cells and want the text to be gathered into
one cell.
The cells with the text are in consecutive rows in one column. I want to
make a macro that gather the text from cells I have selected. How can I do
this

Ex.
Cell A1: "Microsoft"
Cell A2: "Visual"
Cell A3: "Basic"

I select cells A1:A3, run macro and the result is
Cell A1: "Microsoft Visual Basic"

Please help!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Text into one cell

Something like this, perhaps...? (Using Join() would be nicer, but I couldn't
figure out a way to do it. Hopefully someone else will be able to tell you
how to do that.)

Cheers,
/MP

Public Sub ConsolidateMyRange()
Dim t As String
Dim r As Range

' Pre-condition: we want to make sure we've got some
' sensible input before we start joining the values.
If (VarType(Application.Selection) < vbVariant + vbArray) Then
Exit Sub
End If

' Concatenate the values of all selected cells
For Each r In Application.Selection
t = t & r.Value & " "
Next r

' If there is something to output then assign it
' to the first selected cell (trim trailing space)
If Len(t) 0 Then
Application.Selection(1, 1).Value = Left(t, Len(t) - 1)
End If
End Sub



"Trond" wrote:

Hi!

I have text spread in several cells and want the text to be gathered into
one cell.
The cells with the text are in consecutive rows in one column. I want to
make a macro that gather the text from cells I have selected. How can I do
this

Ex.
Cell A1: "Microsoft"
Cell A2: "Visual"
Cell A3: "Basic"

I select cells A1:A3, run macro and the result is
Cell A1: "Microsoft Visual Basic"

Please help!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Text into one cell

Hi
This should do it

Public Sub tester()
Dim Testrange as Range, Cell as Range
Dim TestString as String
On Error Resume Next
Set Testrange = Selection
If Not Testrange Is Nothing Then
For Each Cell In Testrange
TestString = TestString & " " & Cell.Text
Next Cell
Testrange.Cells(1, 1).Value = Trim(TestString)
End If
Set Testrange = Nothing
End Sub

The error message bit is just in case you have graphic or some such
selected.
regards
Paul

Trond wrote:
Hi!

I have text spread in several cells and want the text to be gathered into
one cell.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enter text in a cell to return a text value in same cell Danno 24/7[_2_] Excel Discussion (Misc queries) 6 May 9th 08 06:26 AM
Find text in a cell and copy text to another cell Shaun Excel Discussion (Misc queries) 6 July 4th 07 05:25 PM
Copy text from cell to cell with one cell changing text Bobby Excel Worksheet Functions 5 March 15th 07 11:09 PM
Deleting Rows based on text in cell & formatting cell based on text in column beside it Steve Excel Programming 4 February 26th 04 03:31 PM
extracting text from within a cell - 'text to rows@ equivalent of 'text to columns' Dan E[_2_] Excel Programming 4 July 30th 03 06:43 PM


All times are GMT +1. The time now is 03:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"