Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default quicker cell concatenation

Dear experts,
I want to fill in a range (column) with concatenation data from other 4
columns.
The number of rows is quite big so it takes a while before vba can finish
the task. My code looks like
For i = 1 to LastRow
Cells(i, 7)=Cells(i,1) & Cells(7,2) & Cells(i,3) & Cells(1,4) & Cells(i,5) &
Cells(i,6)
Next i

Is there another way to do this more quickly, maybe playing with ranges?
Thanks a lot for your advice.
Kind regards

--
Valeria
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default quicker cell concatenation

Hi

Turn off screenupdating and set calculation to manual, just remember
to set it back again:

Sub aaa()
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

For i = 1 to LastRow
Cells(i, 7)=Cells(i,1) & Cells(7,2) & Cells(i,3) & Cells(1,4) &
Cells(i,5) &
Cells(i,6)
Next i

With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub

Regards,
Per

On 28 Apr., 13:23, Valeria wrote:
Dear experts,
I want to fill in a range (column) with concatenation data from other 4
columns.
The number of rows is quite big so it takes a while before vba can finish
the task. My code looks like
For i = 1 to LastRow
Cells(i, 7)=Cells(i,1) & Cells(7,2) & Cells(i,3) & Cells(1,4) & Cells(i,5) &
Cells(i,6)
Next i

Is there another way to do this more quickly, maybe playing with ranges?
Thanks a lot for your advice.
Kind regards

--
Valeria


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default quicker cell concatenation

Try replacing the loop with something like this:

Const newFormula = "=RC[-6] & R7C2 & RC[-4] & R1C4 & RC[-2] & RC[-1]"
Dim changeRange As Range

Set changeRange = Range(Cells(1, 7), Cells(lastRow, 7))
Application.ScreenUpdating = False
changeRange.FormulaR1C1 = newFormula
'if you need "hard values"
changeRange.Formula = changeRange.Value



"Valeria" wrote:

Dear experts,
I want to fill in a range (column) with concatenation data from other 4
columns.
The number of rows is quite big so it takes a while before vba can finish
the task. My code looks like
For i = 1 to LastRow
Cells(i, 7)=Cells(i,1) & Cells(7,2) & Cells(i,3) & Cells(1,4) & Cells(i,5) &
Cells(i,6)
Next i

Is there another way to do this more quickly, maybe playing with ranges?
Thanks a lot for your advice.
Kind regards

--
Valeria

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default quicker cell concatenation

Try the below non-looping code

Range(Cells(1, 7), Cells(lastRow, 7)).Formula = "=A1&B1&C1&D1&E1&F1"
Range(Cells(1, 7), Cells(lastRow, 7)) = Range(Cells(1, 7), Cells(lastRow,
7)).Value


--
Jacob (MVP - Excel)


"Valeria" wrote:

Dear experts,
I want to fill in a range (column) with concatenation data from other 4
columns.
The number of rows is quite big so it takes a while before vba can finish
the task. My code looks like
For i = 1 to LastRow
Cells(i, 7)=Cells(i,1) & Cells(7,2) & Cells(i,3) & Cells(1,4) & Cells(i,5) &
Cells(i,6)
Next i

Is there another way to do this more quickly, maybe playing with ranges?
Thanks a lot for your advice.
Kind regards

--
Valeria

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default quicker cell concatenation

The second line split to two....

Range(Cells(1, 7), Cells(lastRow, 7)).Formula = "=A1&B1&C1&D1&E1&F1"
Range(Cells(1, 7), Cells(lastRow, 7)) = _
Range(Cells(1, 7), Cells(lastRow, 7)).Value


--
Jacob (MVP - Excel)


"Jacob Skaria" wrote:

Try the below non-looping code

Range(Cells(1, 7), Cells(lastRow, 7)).Formula = "=A1&B1&C1&D1&E1&F1"
Range(Cells(1, 7), Cells(lastRow, 7)) = Range(Cells(1, 7), Cells(lastRow,
7)).Value


--
Jacob (MVP - Excel)


"Valeria" wrote:

Dear experts,
I want to fill in a range (column) with concatenation data from other 4
columns.
The number of rows is quite big so it takes a while before vba can finish
the task. My code looks like
For i = 1 to LastRow
Cells(i, 7)=Cells(i,1) & Cells(7,2) & Cells(i,3) & Cells(1,4) & Cells(i,5) &
Cells(i,6)
Next i

Is there another way to do this more quickly, maybe playing with ranges?
Thanks a lot for your advice.
Kind regards

--
Valeria



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default quicker cell concatenation

I am baffled - both solutions (Jabob and JLatham) work beautifully and make
me save at least 20 min/run! Thanks a lot!
--
Valeria


"Jacob Skaria" wrote:

The second line split to two....

Range(Cells(1, 7), Cells(lastRow, 7)).Formula = "=A1&B1&C1&D1&E1&F1"
Range(Cells(1, 7), Cells(lastRow, 7)) = _
Range(Cells(1, 7), Cells(lastRow, 7)).Value


--
Jacob (MVP - Excel)


"Jacob Skaria" wrote:

Try the below non-looping code

Range(Cells(1, 7), Cells(lastRow, 7)).Formula = "=A1&B1&C1&D1&E1&F1"
Range(Cells(1, 7), Cells(lastRow, 7)) = Range(Cells(1, 7), Cells(lastRow,
7)).Value


--
Jacob (MVP - Excel)


"Valeria" wrote:

Dear experts,
I want to fill in a range (column) with concatenation data from other 4
columns.
The number of rows is quite big so it takes a while before vba can finish
the task. My code looks like
For i = 1 to LastRow
Cells(i, 7)=Cells(i,1) & Cells(7,2) & Cells(i,3) & Cells(1,4) & Cells(i,5) &
Cells(i,6)
Next i

Is there another way to do this more quickly, maybe playing with ranges?
Thanks a lot for your advice.
Kind regards

--
Valeria

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default quicker cell concatenation

The two are pretty much the same, except that mine uses R1C1 format for the
formula, and Jacob's uses the more familar addressing. Also, in mine, I did
reference $B$7 ( R7C2 ) and $D$1 ( R1C4 ) absolutely as per your code
example. I wasn't certain that's what you wanted to do, so I just emulated
your loop code literally.

The amazing part of it all is that Excel does all of the work for you, and
does it fast. Your own loop would probably increase speed dramatically if
you simply added
Application.ScreenUpdating=False
just before the loop starts. That alone can reduce time-to-complet for such
things by huge amounts. Making changes via an object reference as was done
by both myself and Jacob, is equally stunning in its results in most cases.
But after you've turned off ScreenUpdating, it becomes hard to measure the
added improvement of simply referencing objects rather than 'directly'
addressing them on a worksheet or in a workbook.

"Valeria" wrote:

I am baffled - both solutions (Jabob and JLatham) work beautifully and make
me save at least 20 min/run! Thanks a lot!
--
Valeria


"Jacob Skaria" wrote:

The second line split to two....

Range(Cells(1, 7), Cells(lastRow, 7)).Formula = "=A1&B1&C1&D1&E1&F1"
Range(Cells(1, 7), Cells(lastRow, 7)) = _
Range(Cells(1, 7), Cells(lastRow, 7)).Value


--
Jacob (MVP - Excel)


"Jacob Skaria" wrote:

Try the below non-looping code

Range(Cells(1, 7), Cells(lastRow, 7)).Formula = "=A1&B1&C1&D1&E1&F1"
Range(Cells(1, 7), Cells(lastRow, 7)) = Range(Cells(1, 7), Cells(lastRow,
7)).Value


--
Jacob (MVP - Excel)


"Valeria" wrote:

Dear experts,
I want to fill in a range (column) with concatenation data from other 4
columns.
The number of rows is quite big so it takes a while before vba can finish
the task. My code looks like
For i = 1 to LastRow
Cells(i, 7)=Cells(i,1) & Cells(7,2) & Cells(i,3) & Cells(1,4) & Cells(i,5) &
Cells(i,6)
Next i

Is there another way to do this more quickly, maybe playing with ranges?
Thanks a lot for your advice.
Kind regards

--
Valeria

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default quicker cell concatenation

Valeria,

If you are still following this thread, the following macro should do what
you want and appears to be exceedingly fast (it did a sample of 10,000 rows,
literally, in the blink of an eye)...

Sub ConcatAthruF()
Dim X As Long, LastRow As Long, Vin As Variant, Vout As Variant
LastRow = Range("A:F").Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
Vin = Range("A1:F" & LastRow)
ReDim Vout(1 To LastRow)
For X = 1 To LastRow
Vout(X) = Vin(X, 1) & Vin(X, 2) & Vin(X, 3) & _
Vin(X, 4) & Vin(X, 5) & Vin(X, 6)
Next
Range("G1").Resize(LastRow) = Vout
End Sub

--
Rick (MVP - Excel)



"Valeria" wrote in message
...
Dear experts,
I want to fill in a range (column) with concatenation data from other 4
columns.
The number of rows is quite big so it takes a while before vba can finish
the task. My code looks like
For i = 1 to LastRow
Cells(i, 7)=Cells(i,1) & Cells(7,2) & Cells(i,3) & Cells(1,4) & Cells(i,5)
&
Cells(i,6)
Next i

Is there another way to do this more quickly, maybe playing with ranges?
Thanks a lot for your advice.
Kind regards

--
Valeria


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default quicker cell concatenation

Sorry, I posted the wrong version of the code (one of my old test lines was
left in it instead of the correct one). This code still executes 10,000 rows
of concatenations in the blink of an eye...

Sub ConcatAthruF()
Dim X As Long, LastRow As Long, Vin As Variant, Vout As Variant
LastRow = Range("A:F").Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
Vin = Range("A1:F" & LastRow)
ReDim Vout(1 To LastRow)
For X = 1 To LastRow
Vout(X) = Vin(X, 1) & Vin(X, 2) & Vin(X, 3) & _
Vin(X, 4) & Vin(X, 5) & Vin(X, 6)
Next
Range("G1").Resize(LastRow) = WorksheetFunction.Transpose(Vout)
End Sub

--
Rick (MVP - Excel)



"Rick Rothstein" wrote in message
...
Valeria,

If you are still following this thread, the following macro should do what
you want and appears to be exceedingly fast (it did a sample of 10,000
rows, literally, in the blink of an eye)...

Sub ConcatAthruF()
Dim X As Long, LastRow As Long, Vin As Variant, Vout As Variant
LastRow = Range("A:F").Find(What:="*", SearchOrder:=xlColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
Vin = Range("A1:F" & LastRow)
ReDim Vout(1 To LastRow)
For X = 1 To LastRow
Vout(X) = Vin(X, 1) & Vin(X, 2) & Vin(X, 3) & _
Vin(X, 4) & Vin(X, 5) & Vin(X, 6)
Next
Range("G1").Resize(LastRow) = Vout
End Sub

--
Rick (MVP - Excel)



"Valeria" wrote in message
...
Dear experts,
I want to fill in a range (column) with concatenation data from other 4
columns.
The number of rows is quite big so it takes a while before vba can finish
the task. My code looks like
For i = 1 to LastRow
Cells(i, 7)=Cells(i,1) & Cells(7,2) & Cells(i,3) & Cells(1,4) &
Cells(i,5) &
Cells(i,6)
Next i

Is there another way to do this more quickly, maybe playing with ranges?
Thanks a lot for your advice.
Kind regards

--
Valeria


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
Reverse Concatenation (Splitting Single Cell Data into Multiple Ce SirEric Excel Discussion (Misc queries) 5 November 14th 08 09:39 AM
Return to 1st cell in next line in multi-column list for quicker e Katijo Excel Worksheet Functions 3 October 10th 08 06:32 AM
dynamic rows: cell value concatenation deepika :excel help[_2_] Excel Discussion (Misc queries) 1 January 30th 08 11:35 AM
quicker copydown Naz Excel Programming 9 November 20th 06 03:43 AM
Cell problems - need a quicker way. lara5555 Excel Worksheet Functions 2 January 13th 06 01:00 PM


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