Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default copy contents of multiple cells into a new cell - Help Needed Please

Hello,

In what has turned out to be a massive project, I am reaching the final
stages.
However I need a macro to automate a tedius task, and was hoping that
some of you out there might be able to provide one or at least part of
one. I have tried to be as articulate and specific as possible in
explaining what i need so here goes...

For a given row y ; copy the contents of every 4th column to a
concatenated string, and paste this string into the column labeled GOD
(i'm using excel 2007 - because i ran out of columns in excel 2003!) of
row y. The contents of each column that forms part of the string should
be seperated by six spaces, i.e. " ".

I need the macro to run this for every row in the worksheet.
(there are about 2000 rows, and one row has 5125 columns!

I look forward to your thoughts,

Gary.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default copy contents of multiple cells into a new cell - Help Needed Please

Gary,
Personally, if you need 5000+ columns, your structure needs to be rewored,
but...
Need sometidying up, but it Friday night and off to the pub. I 'll see what
I can do over the weekend:

Private Sub CommandButton1_Click()
Dim RowIndex As Long
Dim ColumnIndex As Long
Dim CelVal As String
Dim TempStr As String
Dim DestColumn As Long

Const COLUMN_STEP As Long = 4
Const SPACER As Long = 6

With ActiveCell.CurrentRegion
DestColumn = .Columns.Count + COLUMN_STEP
For RowIndex = 0 To .Rows.Count - 1
With .Range("A1").Offset(RowIndex, 0)
TempStr = ""
ColumnIndex = COLUMN_STEP
CelVal = .Offset(0, ColumnIndex).Value
Do Until CelVal = ""
TempStr = TempStr & CelVal & Space(SPACER)
ColumnIndex = ColumnIndex + COLUMN_STEP
CelVal = .Offset(0, ColumnIndex).Value
Loop
Debug.Print TempStr
If Len(TempStr) 0 Then ActiveCell.CurrentRegion.Cells(RowIndex
+ 1, DestColumn).Value = Left(TempStr, Len(TempStr) - SPACER)
End With
Next
End With
End Sub

Try it on a 20 x 20 selection of you data first to make sure it's giving the
correct result.
Exact size doesn't matter, as it works on .CurrentRegion, so selct any cell
in the data and click go.

NickHK



groups.com...
Hello,

In what has turned out to be a massive project, I am reaching the final
stages.
However I need a macro to automate a tedius task, and was hoping that
some of you out there might be able to provide one or at least part of
one. I have tried to be as articulate and specific as possible in
explaining what i need so here goes...

For a given row y ; copy the contents of every 4th column to a
concatenated string, and paste this string into the column labeled GOD
(i'm using excel 2007 - because i ran out of columns in excel 2003!) of
row y. The contents of each column that forms part of the string should
be seperated by six spaces, i.e. " ".

I need the macro to run this for every row in the worksheet.
(there are about 2000 rows, and one row has 5125 columns!

I look forward to your thoughts,

Gary.



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
separate contents of one cell into multiple cells Horacio[_4_] Excel Worksheet Functions 4 January 24th 10 12:25 AM
Excel 2000 - Split Contents of Cell Across Multiple Cells DeeW Excel Discussion (Misc queries) 7 November 8th 06 09:10 PM
How do I copy the contents of a range of text cells and paste into one cell? davfin Excel Discussion (Misc queries) 7 July 4th 06 08:16 AM
How do I combine the contents of multiple cells in one cell? Debbie Excel Worksheet Functions 3 December 16th 05 10:57 PM
Help needed with macro: Writing contents of two cells to two new columns Big B Excel Programming 0 November 24th 05 04:27 PM


All times are GMT +1. The time now is 12:46 AM.

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"