PC Review


Reply
Thread Tools Rate Thread

Concatenation within a macro

 
 
Risky Dave
Guest
Posts: n/a
 
      22nd Feb 2008
Hi,

I have a large data set that is automatically formatted by a macro. As part
of this macro I need to concatenate sets of three cells into one and format
the output.
Eg. I need to convert:
A B C
1 1Data1 1Data2 1Data3
2 2Data1 2Data2 2Data3
3 3Data1 3Data2 3Data3

To:
A
1 1Data1
1Data2
1Data3
2 2Data1
2Data2
2Data3
3 3Data1
3Data2
3Data3

The actual output cell can be pretty much anywhere - I can adjust this bit
to fit in with the rest of the formatting.

I can do this by setting up a separate sheet with loads of formulae, but as
there are several hundreds of lines involved (I have no way of knowing
exactly how many), each with about 100 cells, this soon makes the file size
excessively large (especially as there's a load of other stuff going on in
the overall workbook).

Can anyone supply a piece of code that I can drop into the rest of the macro
and will produce the output above?

Although I don't know how many times this needs to be carried out (because I
don't know the exact number of lines with data in them), I can set a high
(eg. 500 or 1000) limit for the number of lines to be formatted - it doesn't
matter if the macro attempts to format cells with no data in them.

Hope this makes sense :-)

If it makes any difference, this is in Office 2003.

TIA Dave
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      22nd Feb 2008
Sub put_um()
Set r = Range("D10")
For j = 1 To 3
v = ""
For i = 1 To 3
v = v & Cells(i, j).Value & Chr(10)
Next
r.Offset(j, 0).Value = v
Next
End Sub

will take your data and put the results in D11, D12, and D13.
--
Gary''s Student - gsnu200770


"Risky Dave" wrote:

> Hi,
>
> I have a large data set that is automatically formatted by a macro. As part
> of this macro I need to concatenate sets of three cells into one and format
> the output.
> Eg. I need to convert:
> A B C
> 1 1Data1 1Data2 1Data3
> 2 2Data1 2Data2 2Data3
> 3 3Data1 3Data2 3Data3
>
> To:
> A
> 1 1Data1
> 1Data2
> 1Data3
> 2 2Data1
> 2Data2
> 2Data3
> 3 3Data1
> 3Data2
> 3Data3
>
> The actual output cell can be pretty much anywhere - I can adjust this bit
> to fit in with the rest of the formatting.
>
> I can do this by setting up a separate sheet with loads of formulae, but as
> there are several hundreds of lines involved (I have no way of knowing
> exactly how many), each with about 100 cells, this soon makes the file size
> excessively large (especially as there's a load of other stuff going on in
> the overall workbook).
>
> Can anyone supply a piece of code that I can drop into the rest of the macro
> and will produce the output above?
>
> Although I don't know how many times this needs to be carried out (because I
> don't know the exact number of lines with data in them), I can set a high
> (eg. 500 or 1000) limit for the number of lines to be formatted - it doesn't
> matter if the macro attempts to format cells with no data in them.
>
> Hope this makes sense :-)
>
> If it makes any difference, this is in Office 2003.
>
> TIA Dave

 
Reply With Quote
 
Risky Dave
Guest
Posts: n/a
 
      22nd Feb 2008
Hi,

Thanks for the quick response.

This is nearly what I am after, but is giving me:

1Data1
2Data1
3Data1

1Data2
2Data2
3Data2

1Data3
2Data3
2Data3

ie. the columns concatenated into each cell, whereas I need the rows
concatenated vertically into each cell.

Thanks.


Dave

"Gary''s Student" wrote:

> Sub put_um()
> Set r = Range("D10")
> For j = 1 To 3
> v = ""
> For i = 1 To 3
> v = v & Cells(i, j).Value & Chr(10)
> Next
> r.Offset(j, 0).Value = v
> Next
> End Sub
>
> will take your data and put the results in D11, D12, and D13.
> --
> Gary''s Student - gsnu200770
>
>
> "Risky Dave" wrote:
>
> > Hi,
> >
> > I have a large data set that is automatically formatted by a macro. As part
> > of this macro I need to concatenate sets of three cells into one and format
> > the output.
> > Eg. I need to convert:
> > A B C
> > 1 1Data1 1Data2 1Data3
> > 2 2Data1 2Data2 2Data3
> > 3 3Data1 3Data2 3Data3
> >
> > To:
> > A
> > 1 1Data1
> > 1Data2
> > 1Data3
> > 2 2Data1
> > 2Data2
> > 2Data3
> > 3 3Data1
> > 3Data2
> > 3Data3
> >
> > The actual output cell can be pretty much anywhere - I can adjust this bit
> > to fit in with the rest of the formatting.
> >
> > I can do this by setting up a separate sheet with loads of formulae, but as
> > there are several hundreds of lines involved (I have no way of knowing
> > exactly how many), each with about 100 cells, this soon makes the file size
> > excessively large (especially as there's a load of other stuff going on in
> > the overall workbook).
> >
> > Can anyone supply a piece of code that I can drop into the rest of the macro
> > and will produce the output above?
> >
> > Although I don't know how many times this needs to be carried out (because I
> > don't know the exact number of lines with data in them), I can set a high
> > (eg. 500 or 1000) limit for the number of lines to be formatted - it doesn't
> > matter if the macro attempts to format cells with no data in them.
> >
> > Hope this makes sense :-)
> >
> > If it makes any difference, this is in Office 2003.
> >
> > TIA Dave

 
Reply With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      22nd Feb 2008
Use this version instead:

Sub put_um()
Set r = Range("D10")
For i = 1 To 3
v = ""
For j = 1 To 3
v = v & Cells(i, j).Value & Chr(10)
Next
r.Offset(i, 0).Value = v
Next
End Sub
--
Gary''s Student - gsnu200770


"Risky Dave" wrote:

> Hi,
>
> Thanks for the quick response.
>
> This is nearly what I am after, but is giving me:
>
> 1Data1
> 2Data1
> 3Data1
>
> 1Data2
> 2Data2
> 3Data2
>
> 1Data3
> 2Data3
> 2Data3
>
> ie. the columns concatenated into each cell, whereas I need the rows
> concatenated vertically into each cell.
>
> Thanks.
>
>
> Dave
>
> "Gary''s Student" wrote:
>
> > Sub put_um()
> > Set r = Range("D10")
> > For j = 1 To 3
> > v = ""
> > For i = 1 To 3
> > v = v & Cells(i, j).Value & Chr(10)
> > Next
> > r.Offset(j, 0).Value = v
> > Next
> > End Sub
> >
> > will take your data and put the results in D11, D12, and D13.
> > --
> > Gary''s Student - gsnu200770
> >
> >
> > "Risky Dave" wrote:
> >
> > > Hi,
> > >
> > > I have a large data set that is automatically formatted by a macro. As part
> > > of this macro I need to concatenate sets of three cells into one and format
> > > the output.
> > > Eg. I need to convert:
> > > A B C
> > > 1 1Data1 1Data2 1Data3
> > > 2 2Data1 2Data2 2Data3
> > > 3 3Data1 3Data2 3Data3
> > >
> > > To:
> > > A
> > > 1 1Data1
> > > 1Data2
> > > 1Data3
> > > 2 2Data1
> > > 2Data2
> > > 2Data3
> > > 3 3Data1
> > > 3Data2
> > > 3Data3
> > >
> > > The actual output cell can be pretty much anywhere - I can adjust this bit
> > > to fit in with the rest of the formatting.
> > >
> > > I can do this by setting up a separate sheet with loads of formulae, but as
> > > there are several hundreds of lines involved (I have no way of knowing
> > > exactly how many), each with about 100 cells, this soon makes the file size
> > > excessively large (especially as there's a load of other stuff going on in
> > > the overall workbook).
> > >
> > > Can anyone supply a piece of code that I can drop into the rest of the macro
> > > and will produce the output above?
> > >
> > > Although I don't know how many times this needs to be carried out (because I
> > > don't know the exact number of lines with data in them), I can set a high
> > > (eg. 500 or 1000) limit for the number of lines to be formatted - it doesn't
> > > matter if the macro attempts to format cells with no data in them.
> > >
> > > Hope this makes sense :-)
> > >
> > > If it makes any difference, this is in Office 2003.
> > >
> > > TIA Dave

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
concatenation w/in a macro wilson@irco Microsoft Excel Misc 2 14th Apr 2008 02:58 PM
Concatenation =?Utf-8?B?Sm9hbm5l?= Microsoft Access Queries 1 29th Jan 2007 06:43 PM
Concatenation =?Utf-8?B?SkthcmNobmVy?= Microsoft Access Queries 7 24th Jul 2006 03:55 PM
concatenation ccw Microsoft Access Database Table Design 1 13th Jan 2004 06:15 PM
concatenation Cathy Microsoft Excel Worksheet Functions 4 11th Oct 2003 06:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:23 AM.