Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,441
Default Combining various numbers of cells without using the & or concaten

Ken,

This should clear the other cells:

Sub CombCell2()
Dim i As Integer
Dim myS As String
Application.EnableEvents = False
myS = Selection.Cells(1).Value
For i = 2 To Selection.Cells.Count
myS = myS & ", " & Selection.Cells(i).Value
Selection.Cells(i).ClearContents
Next i
Selection.Cells(1).Value = myS
Application.EnableEvents = True
End Sub

But if there is information in another column that you use to decide what cells to combine, the
macro could be rewritten to choose the cells automatically instead of you doing it manually - the
whole column could be done in a matter of seconds.

Try to describe your basis of choosing cells....

HTH,
Bernie
MS Excel MVP


"Ken Peterson" wrote in message
...
Hi Bernie,

Thank you very much, especially for the very fast response. That is exactly
what I was looking for. I would delete the values in cells a2:a4 and then
copy the value in a1 to cells a2:a4. If you could add the ability to delete
cells a2:a4 (or whatever was selected) after the combination occurs that
would be very helpful.

The reason I need to do this is that once the cells are combined I need to
subsequently copy that cell (a1) to a number of adjacent cells in the same
column (the number of cells may or may not be equal to the number of
combined cells). This is so we can see how many records each client has in
the rows for that client. Each clint may have different information in
various columns on each row.

Thanks again,
Ken


"Bernie Deitrick" wrote:

Ken,

Select your cells and run this macro:

Sub CombCell()
Dim i As Integer
Dim myS As String
myS = Selection.Cells(1).Value
For i = 2 To Selection.Cells.Count
myS = myS & ", " & Selection.Cells(i).Value
Next i
Application.EnableEvents = False
Selection.Cells(1).Value = myS
Application.EnableEvents = True
End Sub

But is there logic to how you select cells? Certainly, that can be coded in. And what do you do
with
the values in cells A2:A4?

HTH,
Bernie
MS Excel MVP


"Ken Peterson" wrote in message
...
I have over 16,000 rows of data. In the first column I need to combine
cosecutive cells. The number of cells to be combined varies. For example, I
may need to combine cells a1, a1, a3, a4 in one instance; cells a100, a101 in
another instance; cells a5200:a5220 in another instance; depending on the
cells in the other columns. The combined cells need to be comma-delimited.

I know I can use =A1&" "&A2 or =concatenate(a1,a2) or =concatenate
(a5200:a5220), etc. However, this is tedious because I have to manually do
this throughout all 16,000 rows.

What I would like to do is highlight the cells that need to be combined and
use a keystroke or two to combine them.

For example,

The first instance of cells to be combined is:
cell a1 = 1245-aw
cell a2 = 5241-ed
cell a3 = 3464-th
cell a4 = 156302-yu

After using the keystrokes, I want the result in cell a1 to look like
"1245aw, 5241-ed, 3464-th, 156302-yu" (without the quotes). There will be
between 2 and 20 cells to be combined, numerous times throughout the
worksheet. Right now I have use cut and paste for every instance to be
combined.

Thank you for your anticipated help.






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
Count cells with numbers and ignore cells with errors WonderingaboutMicrosoft Excel Discussion (Misc queries) 6 December 10th 06 08:03 PM
change 2000 cells (negative numbers) into positive numbers lisbern Excel Worksheet Functions 2 August 16th 06 05:54 PM
Sorting - cells containing numbers, numbers and letters Gunny Excel Discussion (Misc queries) 5 July 16th 06 01:22 AM
Hightlighting Numbers & then all Cells to the right of these Numbers. Dave Excel Worksheet Functions 4 August 29th 05 10:30 PM
Cobining more than 30 columns of data with concatenate. JT Excel Worksheet Functions 11 May 29th 05 03:10 AM


All times are GMT +1. The time now is 12:39 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"